Directly call write state 2 (#33513)

* Directly call async_write_ha_state pt2

* Directly call async_write_ha_state pt2

* Fix mock

* Address comments
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-03 09:34:50 +02:00
1 parent 83cc871edf
commit aef06a3544
40 files changed
+127 -117

No files matched your search

+3 -8
View File
@@ -1,5 +1,4 @@
"""SMA Solar Webconnect interface."""
import asyncio
from datetime import timedelta
import logging
@@ -163,13 +162,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
return
backoff_step = 0
tasks = []
for sensor in hass_sensors:
task = sensor.async_update_values()
if task:
tasks.append(task)
if tasks:
await asyncio.wait(tasks)
sensor.async_update_values()
interval = config.get(CONF_SCAN_INTERVAL) or timedelta(seconds=5)
async_track_time_interval(hass, async_sma, interval)
@@ -226,7 +220,8 @@ class SMAsensor(Entity):
update = True
self._state = self._sensor.value
return self.async_update_ha_state() if update else None
if update:
self.async_write_ha_state()
@property
def unique_id(self):