Enable homeassistant.update_entity service for all modbus platforms (#49918)

* Rename _update() to update()

A platform neeed a function update(), even though
polling is false, this is due to the service:
homeassistant.update_entity, which calls update()

* Update test harnesss to script testing.

Test homeassistant.update_entity in all platforms.
This call calls update() in the platform to get
a new reading.

* Add reuse parameter.

* Move service call from helper to tests.

* Change run_service_update --> prepare_service_update.

* Remove entity_id parameter.
This commit is contained in:
jan iversen 2021-05-02 10:41:36 +02:00 committed by GitHub
parent 1bd9826684
commit 8adbc62a6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 188 additions and 21 deletions

View file

@ -129,7 +129,7 @@ class ModbusBinarySensor(BinarySensorEntity):
async def async_added_to_hass(self):
"""Handle entity which will be added."""
async_track_time_interval(
self.hass, lambda arg: self._update(), self._scan_interval
self.hass, lambda arg: self.update(), self._scan_interval
)
@property
@ -162,7 +162,7 @@ class ModbusBinarySensor(BinarySensorEntity):
"""Return True if entity is available."""
return self._available
def _update(self):
def update(self):
"""Update the state of the sensor."""
if self._input_type == CALL_TYPE_COIL:
result = self._hub.read_coils(self._slave, self._address, 1)