mirror of
https://github.com/home-assistant/android
synced 2024-09-19 16:11:37 +00:00
Breaking Change: Only send updates when a state change has been detected (#891)
This commit is contained in:
parent
e84abafa78
commit
c0d4b225ed
|
@ -30,7 +30,7 @@ import io.homeassistant.companion.android.database.widget.TemplateWidgetEntity
|
|||
StaticWidgetEntity::class,
|
||||
TemplateWidgetEntity::class
|
||||
],
|
||||
version = 8
|
||||
version = 9
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun authenticationDao(): AuthenticationDao
|
||||
|
@ -63,7 +63,8 @@ abstract class AppDatabase : RoomDatabase() {
|
|||
MIGRATION_4_5,
|
||||
MIGRATION_5_6,
|
||||
MIGRATION_6_7,
|
||||
MIGRATION_7_8
|
||||
MIGRATION_7_8,
|
||||
MIGRATION_8_9
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
@ -162,5 +163,10 @@ abstract class AppDatabase : RoomDatabase() {
|
|||
database.execSQL("ALTER TABLE `sensor_attributes` ADD `value_type` TEXT NOT NULL DEFAULT 'string'")
|
||||
}
|
||||
}
|
||||
private val MIGRATION_8_9 = object : Migration(8, 9) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE `sensors` ADD `state_changed` INTEGER NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ data class Sensor(
|
|||
var enabled: Boolean,
|
||||
@ColumnInfo(name = "registered")
|
||||
var registered: Boolean,
|
||||
@ColumnInfo(name = "state_changed")
|
||||
var stateChanged: Boolean,
|
||||
@ColumnInfo(name = "state")
|
||||
var state: String,
|
||||
@ColumnInfo(name = "state_type")
|
||||
|
|
|
@ -251,6 +251,7 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
|
|||
uniqueId,
|
||||
isChecked,
|
||||
false,
|
||||
true,
|
||||
""
|
||||
)
|
||||
sensorDao.add(sensor)
|
||||
|
|
|
@ -155,7 +155,7 @@ class SensorDetailFragment(
|
|||
sensorEntity.enabled = isEnabled
|
||||
sensorDao.update(sensorEntity)
|
||||
} else {
|
||||
sensorEntity = Sensor(basicSensor.id, isEnabled, false, "")
|
||||
sensorEntity = Sensor(basicSensor.id, isEnabled, false, true, "")
|
||||
sensorDao.add(sensorEntity)
|
||||
}
|
||||
refreshSensorData()
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.pm.PackageManager
|
||||
import android.os.Process.myPid
|
||||
import android.os.Process.myUid
|
||||
import android.util.Log
|
||||
import io.homeassistant.companion.android.R
|
||||
import io.homeassistant.companion.android.database.AppDatabase
|
||||
import io.homeassistant.companion.android.database.sensor.Attribute
|
||||
|
@ -39,7 +40,7 @@ interface SensorManager {
|
|||
|
||||
// If we haven't created the entity yet do so and default to enabled if required
|
||||
if (sensor == null) {
|
||||
sensor = Sensor(sensorId, permission && enabledByDefault, false, "")
|
||||
sensor = Sensor(sensorId, permission && enabledByDefault, false, true, "")
|
||||
sensorDao.add(sensor)
|
||||
}
|
||||
|
||||
|
@ -67,6 +68,8 @@ interface SensorManager {
|
|||
) {
|
||||
val sensorDao = AppDatabase.getInstance(context).sensorDao()
|
||||
val sensor = sensorDao.get(basicSensor.id) ?: return
|
||||
Log.d("SensorManager", "Old sensor state ${sensor.state} compared to new state $state for ${sensor.name}")
|
||||
sensor.stateChanged = (sensor.state != state.toString())
|
||||
sensor.id = basicSensor.id
|
||||
sensor.state = state.toString()
|
||||
sensor.stateType = when (state) {
|
||||
|
|
|
@ -124,7 +124,7 @@ class SensorReceiver : BroadcastReceiver() {
|
|||
Log.e(TAG, "Issue registering sensor: ${reg.uniqueId}", e)
|
||||
}
|
||||
}
|
||||
if (sensor?.enabled == true && fullSensor != null && sensor?.registered) {
|
||||
if (sensor?.enabled == true && fullSensor != null && sensor?.registered && sensor?.stateChanged) {
|
||||
enabledRegistrations.add(fullSensor.toSensorRegistration())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue