Convert last properties in modbus to _attr_variable (#53919)

This commit is contained in:
jan iversen 2021-08-08 23:23:21 +02:00 committed by GitHub
parent e8aa280d7f
commit 02459e6813
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 74 deletions

View file

@ -43,14 +43,7 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
await self.async_base_added_to_hass()
state = await self.async_get_last_state()
if state:
self._value = state.state == STATE_ON
else:
self._value = None
@property
def is_on(self):
"""Return the state of the sensor."""
return self._value
self._attr_is_on = state.state == STATE_ON
async def async_update(self, now=None):
"""Update the state of the sensor."""
@ -68,6 +61,6 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
self.async_write_ha_state()
return
self._value = result.bits[0] & 1
self._attr_is_on = result.bits[0] & 1
self._attr_available = True
self.async_write_ha_state()