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

+4 -9
View File
@@ -1,5 +1,4 @@
"""SAJ solar inverter interface."""
import asyncio
from datetime import date
import logging
@@ -100,8 +99,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async def async_saj():
"""Update all the SAJ sensors."""
tasks = []
values = await saj.read(sensor_def)
for sensor in hass_sensors:
@@ -118,11 +115,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
not sensor.per_day_basis and not sensor.per_total_basis
):
state_unknown = True
task = sensor.async_update_values(unknown_state=state_unknown)
if task:
tasks.append(task)
if tasks:
await asyncio.wait(tasks)
sensor.async_update_values(unknown_state=state_unknown)
return values
def start_update_interval(event):
@@ -237,7 +231,8 @@ class SAJsensor(Entity):
update = True
self._state = None
return self.async_update_ha_state() if update else None
if update:
self.async_write_ha_state()
@property
def unique_id(self):