Add lazy_error_count to modbus (#54412)

* Add lazy_error_count.

* Use -=

* Review comments.
This commit is contained in:
jan iversen 2021-08-21 15:49:50 +02:00 committed by GitHub
parent 51434c5faa
commit 33f660118f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 47 additions and 1 deletions

View file

@ -57,10 +57,15 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
)
self._call_active = False
if result is None:
if self._lazy_errors:
self._lazy_errors -= 1
return
self._lazy_errors = self._lazy_error_count
self._attr_available = False
self.async_write_ha_state()
return
self._lazy_errors = self._lazy_error_count
self._attr_is_on = result.bits[0] & 1
self._attr_available = True
self.async_write_ha_state()