Skip to content

Commit

Permalink
ayla: DeviceControl: Add missing exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto97 committed Apr 19, 2022
1 parent ba380b5 commit 87f22a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.alberto97.aircontroller.provider.ayla.repositories

import android.util.Log
import org.alberto97.aircontroller.common.features.*
import org.alberto97.aircontroller.common.features.TemperatureExtensions.isCelsius
import org.alberto97.aircontroller.common.features.TemperatureExtensions.toC
Expand All @@ -26,6 +27,9 @@ internal class DeviceControlRepository(
private val tempUnitConverter: ITempUnitConverter,
private val sleepModeConverter: ISleepModeConverter
) : IDeviceControlRepository {
companion object {
private const val LOG_TAG = "HiDeviceControl"
}

override suspend fun getDeviceState(dsn: String): ResultWrapper<AppDeviceState> {
val deviceState = AppDeviceState()
Expand All @@ -35,6 +39,7 @@ internal class DeviceControlRepository(
} catch (e: Exception) {
if (e is IOException)
return DefaultErrors.connectivityError()
Log.e(LOG_TAG, e.stackTraceToString())
return ResultWrapper.Error("Cannot retrieve device state")
}

Expand Down Expand Up @@ -73,7 +78,7 @@ internal class DeviceControlRepository(
return ResultWrapper.Success(deviceState)
}

private fun mapByType(prop: Property) : Any? {
private fun mapByType(prop: Property): Any? {
prop.value ?: return null

return when (prop.baseType) {
Expand Down Expand Up @@ -150,6 +155,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, HORIZONTAL_AIR_FLOW_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update horizontal air flow")
}
}
Expand All @@ -160,6 +166,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, VERTICAL_AIR_FLOW_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update vertical air flow")
}
}
Expand All @@ -170,6 +177,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, BACKLIGHT_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update backlight")
}
}
Expand All @@ -180,6 +188,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, BOOST_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update boost mode")
}
}
Expand All @@ -190,6 +199,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, ECO_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update eco mode")
}
}
Expand All @@ -200,8 +210,9 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, FAN_SPEED_PROP, data)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
ResultWrapper.Error("Cannot update fan speed")
}
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update fan speed")
}
}

override suspend fun setMode(dsn: String, value: WorkMode): ResultWrapper<Unit> {
Expand All @@ -210,6 +221,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, WORK_MODE_PROP, data)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update work mode")
}
}
Expand All @@ -220,6 +232,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, POWER_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update power status")
}
}
Expand All @@ -230,6 +243,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, QUIET_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update quiet mode")
}
}
Expand All @@ -240,6 +254,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, SLEEP_MODE_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update sleep mode")
}
}
Expand All @@ -252,6 +267,7 @@ internal class DeviceControlRepository(
propertyRepo.setProperty(dsn, TEMP_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot update temperature")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ internal class DeviceRepository(
prefs.setTempUnit(dsn, unit)
ResultWrapper.Success(unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot get temperature unit")
}
}
Expand All @@ -92,6 +93,7 @@ internal class DeviceRepository(
propertyRepo.setProperty(dsn, TEMP_TYPE_PROP, datapoint)
ResultWrapper.Success(Unit)
} catch (e: Exception) {
Log.e(LOG_TAG, e.stackTraceToString())
ResultWrapper.Error("Cannot set temperature unit")
}
}
Expand Down

0 comments on commit 87f22a8

Please sign in to comment.