Cleanup async handling (#6388)
* Cleanups unneeded blocks * Cleanup bootstrap * dedicated update_ha_state * Fix imap_email_content * fx tests * Fix lint & spell
This commit is contained in:
1 parent
3044aecbe9
commit
8232f1ef65
30 files changed
+124
-108
No files matched your search
@@ -67,7 +67,7 @@ class EnOceanBinarySensor(enocean.EnOceanDevice, BinarySensorDevice):
|
||||
This method is called when there is an incoming packet associated
|
||||
with this platform.
|
||||
"""
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
if value2 == 0x70:
|
||||
self.which = 0
|
||||
self.onoff = 0
|
||||
|
||||
@@ -216,7 +216,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
|
||||
self.set_value(
|
||||
class_id=zwave.const.COMMAND_CLASS_THERMOSTAT_SETPOINT,
|
||||
index=self._index, data=temperature)
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def set_fan_mode(self, fan):
|
||||
"""Set new target fan mode."""
|
||||
|
||||
@@ -231,7 +231,7 @@ class ISYDevice(Entity):
|
||||
# pylint: disable=unused-argument
|
||||
def on_update(self, event: object) -> None:
|
||||
"""Handle the update event from the ISY994 Node."""
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def domain(self) -> str:
|
||||
|
||||
@@ -106,4 +106,4 @@ class EnOceanLight(enocean.EnOceanDevice, Light):
|
||||
"""Update the internal state of this device."""
|
||||
self._brightness = math.floor(val / 100.0 * 256.0)
|
||||
self._on_state = bool(val != 0)
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
@@ -98,7 +98,7 @@ class LIFX(object):
|
||||
ipaddr, name, power, hue, sat, bri, kel)
|
||||
bulb.set_power(power)
|
||||
bulb.set_color(hue, sat, bri, kel)
|
||||
bulb.update_ha_state()
|
||||
bulb.schedule_update_ha_state()
|
||||
|
||||
def on_color(self, ipaddr, hue, sat, bri, kel):
|
||||
"""Initialize the light."""
|
||||
@@ -106,7 +106,7 @@ class LIFX(object):
|
||||
|
||||
if bulb is not None:
|
||||
bulb.set_color(hue, sat, bri, kel)
|
||||
bulb.update_ha_state()
|
||||
bulb.schedule_update_ha_state()
|
||||
|
||||
def on_power(self, ipaddr, power):
|
||||
"""Initialize the light."""
|
||||
@@ -114,7 +114,7 @@ class LIFX(object):
|
||||
|
||||
if bulb is not None:
|
||||
bulb.set_power(power)
|
||||
bulb.update_ha_state()
|
||||
bulb.schedule_update_ha_state()
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def poll(self, now):
|
||||
|
||||
@@ -106,7 +106,7 @@ class SCSGateLight(Light):
|
||||
return
|
||||
|
||||
self._toggled = message.toggled
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
command = "off"
|
||||
if self._toggled:
|
||||
|
||||
@@ -71,7 +71,7 @@ def setup_proximity_component(hass, name, config):
|
||||
zone_id, unit_of_measurement)
|
||||
proximity.entity_id = '{}.{}'.format(DOMAIN, proximity_zone)
|
||||
|
||||
proximity.update_ha_state()
|
||||
proximity.schedule_update_ha_state()
|
||||
|
||||
track_state_change(
|
||||
hass, proximity_devices, proximity.check_proximity_state_change)
|
||||
@@ -161,7 +161,7 @@ class Proximity(Entity):
|
||||
self.dist_to = 'not set'
|
||||
self.dir_of_travel = 'not set'
|
||||
self.nearest = 'not set'
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
return
|
||||
|
||||
# At least one device is in the monitored zone so update the entity.
|
||||
@@ -169,7 +169,7 @@ class Proximity(Entity):
|
||||
self.dist_to = 0
|
||||
self.dir_of_travel = 'arrived'
|
||||
self.nearest = devices_in_zone
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
return
|
||||
|
||||
# We can't check proximity because latitude and longitude don't exist.
|
||||
@@ -214,7 +214,7 @@ class Proximity(Entity):
|
||||
self.dir_of_travel = 'unknown'
|
||||
device_state = self.hass.states.get(closest_device)
|
||||
self.nearest = device_state.name
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
return
|
||||
|
||||
# Stop if we cannot calculate the direction of travel (i.e. we don't
|
||||
@@ -223,7 +223,7 @@ class Proximity(Entity):
|
||||
self.dist_to = round(distances_to_zone[entity])
|
||||
self.dir_of_travel = 'unknown'
|
||||
self.nearest = entity_name
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
return
|
||||
|
||||
# Reset the variables
|
||||
@@ -250,7 +250,7 @@ class Proximity(Entity):
|
||||
self.dist_to = round(dist_to_zone)
|
||||
self.dir_of_travel = direction_of_travel
|
||||
self.nearest = entity_name
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
_LOGGER.debug('proximity.%s update entity: distance=%s: direction=%s: '
|
||||
'device=%s', self.friendly_name, round(dist_to_zone),
|
||||
direction_of_travel, entity_name)
|
||||
|
||||
@@ -89,7 +89,7 @@ class QSToggleEntity(object):
|
||||
if value != self._value:
|
||||
self._value = value
|
||||
# pylint: disable=no-member
|
||||
super().update_ha_state() # Part of Entity/ToggleEntity
|
||||
super().schedule_update_ha_state() # Part of Entity/ToggleEntity
|
||||
return self._value
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
|
||||
@@ -92,7 +92,7 @@ def _apply_service(service, service_func, *service_func_args):
|
||||
|
||||
for device in _devices:
|
||||
service_func(device, *service_func_args)
|
||||
device.update_ha_state(True)
|
||||
device.schedule_update_ha_state(True)
|
||||
|
||||
|
||||
def _sync_service(service):
|
||||
|
||||
@@ -334,7 +334,7 @@ class RfxtrxDevice(Entity):
|
||||
"""Update det state of the device."""
|
||||
self._state = state
|
||||
self._brightness = brightness
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def _send_command(self, command, brightness=0):
|
||||
if not self._event:
|
||||
@@ -369,4 +369,4 @@ class RfxtrxDevice(Entity):
|
||||
for _ in range(self.signal_repetitions):
|
||||
self._event.device.send_stop(RFXOBJECT.transport)
|
||||
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
@@ -54,7 +54,7 @@ class EnOceanSensor(enocean.EnOceanDevice, Entity):
|
||||
def value_changed(self, value):
|
||||
"""Update the internal state of the device."""
|
||||
self.power = value
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
||||
@@ -169,4 +169,4 @@ class FritzBoxCallMonitor(object):
|
||||
self._sensor.set_state(VALUE_DISCONNECT)
|
||||
att = {"duration": line[3], "closed": isotime}
|
||||
self._sensor.set_attributes(att)
|
||||
self._sensor.update_ha_state()
|
||||
self._sensor.schedule_update_ha_state()
|
||||
@@ -110,7 +110,7 @@ class HaveIBeenPwnedSensor(Entity):
|
||||
|
||||
if self._email in self._data.data:
|
||||
self._state = len(self._data.data[self._email])
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def update(self):
|
||||
"""Update data and see if it contains data for our email."""
|
||||
|
||||
@@ -225,25 +225,23 @@ class EmailContentSensor(Entity):
|
||||
|
||||
def update(self):
|
||||
"""Read emails and publish state change."""
|
||||
while True:
|
||||
email_message = self._email_reader.read_next()
|
||||
email_message = self._email_reader.read_next()
|
||||
|
||||
if email_message is None:
|
||||
break
|
||||
if email_message is None:
|
||||
return
|
||||
|
||||
if self.sender_allowed(email_message):
|
||||
message_body = EmailContentSensor.get_msg_text(email_message)
|
||||
if self.sender_allowed(email_message):
|
||||
message_body = EmailContentSensor.get_msg_text(email_message)
|
||||
|
||||
if self._value_template is not None:
|
||||
message_body = self.render_template(email_message)
|
||||
if self._value_template is not None:
|
||||
message_body = self.render_template(email_message)
|
||||
|
||||
self._message = message_body
|
||||
self._state_attributes = {
|
||||
ATTR_FROM:
|
||||
EmailContentSensor.get_msg_sender(email_message),
|
||||
ATTR_SUBJECT:
|
||||
EmailContentSensor.get_msg_subject(email_message),
|
||||
ATTR_DATE:
|
||||
email_message['Date']
|
||||
}
|
||||
self.update_ha_state()
|
||||
self._message = message_body
|
||||
self._state_attributes = {
|
||||
ATTR_FROM:
|
||||
EmailContentSensor.get_msg_sender(email_message),
|
||||
ATTR_SUBJECT:
|
||||
EmailContentSensor.get_msg_subject(email_message),
|
||||
ATTR_DATE:
|
||||
email_message['Date']
|
||||
}
|
||||
@@ -121,7 +121,7 @@ class LoopEnergyDevice(Entity):
|
||||
return self._unit_of_measurement
|
||||
|
||||
def _callback(self):
|
||||
self.update_ha_state(True)
|
||||
self.schedule_update_ha_state(True)
|
||||
|
||||
|
||||
class LoopEnergyElec(LoopEnergyDevice):
|
||||
|
||||
@@ -89,7 +89,7 @@ class PilightSensor(Entity):
|
||||
try:
|
||||
value = call.data[self._variable]
|
||||
self._state = value
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
except KeyError:
|
||||
_LOGGER.error(
|
||||
'No variable %s in received code data %s',
|
||||
|
||||
@@ -231,7 +231,7 @@ class Sun(Entity):
|
||||
def point_in_time_listener(self, now):
|
||||
"""Called when the state of the sun has changed."""
|
||||
self.update_as_of(now)
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
# Schedule next update at next_change+1 second so sun state has changed
|
||||
track_point_in_utc_time(
|
||||
@@ -241,4 +241,4 @@ class Sun(Entity):
|
||||
def timer_update(self, time):
|
||||
"""Needed to update solar elevation and azimuth."""
|
||||
self.update_sun_position(time)
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
@@ -188,13 +188,13 @@ class BroadlinkRMSwitch(SwitchDevice):
|
||||
"""Turn the device on."""
|
||||
if self._sendpacket(self._command_on):
|
||||
self._state = True
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
if self._sendpacket(self._command_off):
|
||||
self._state = False
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def _sendpacket(self, packet, retry=2):
|
||||
"""Send packet to device."""
|
||||
|
||||
@@ -114,10 +114,10 @@ class RPiRFSwitch(SwitchDevice):
|
||||
"""Turn the switch on."""
|
||||
if self._send_code(self._code_on, self._protocol, self._pulselength):
|
||||
self._state = True
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def turn_off(self):
|
||||
"""Turn the switch off."""
|
||||
if self._send_code(self._code_off, self._protocol, self._pulselength):
|
||||
self._state = False
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
@@ -141,7 +141,7 @@ class SCSGateSwitch(SwitchDevice):
|
||||
return
|
||||
|
||||
self._toggled = message.toggled
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
command = "off"
|
||||
if self._toggled:
|
||||
|
||||
@@ -54,7 +54,7 @@ class Link(Entity):
|
||||
self._url = url
|
||||
self._icon = icon
|
||||
self.entity_id = DOMAIN + '.%s' % slugify(name)
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
||||
@@ -115,7 +115,7 @@ def setup(hass, config):
|
||||
"""Force all devices to poll the Wink API."""
|
||||
_LOGGER.info("Refreshing Wink states from API")
|
||||
for entity in hass.data[DOMAIN]['entities']:
|
||||
entity.update_ha_state(True)
|
||||
entity.schedule_update_ha_state(True)
|
||||
hass.services.register(DOMAIN, 'Refresh state from Wink', force_update)
|
||||
|
||||
def pull_new_devices(call):
|
||||
@@ -150,14 +150,14 @@ class WinkDevice(Entity):
|
||||
if message is None:
|
||||
_LOGGER.error("Error on pubnub update for %s "
|
||||
"polling API for current state", self.name)
|
||||
self.update_ha_state(True)
|
||||
self.schedule_update_ha_state(True)
|
||||
else:
|
||||
self.wink.pubnub_update(message)
|
||||
self.update_ha_state()
|
||||
self.schedule_update_ha_state()
|
||||
except (ValueError, KeyError, AttributeError):
|
||||
_LOGGER.error("Error in pubnub JSON for %s "
|
||||
"polling API for current state", self.name)
|
||||
self.update_ha_state(True)
|
||||
self.schedule_update_ha_state(True)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
Reference in new issue
Block a user