mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add cleanup to Ambient PWS (#32888)
This commit is contained in:
parent
1da35e2939
commit
d98432c328
@ -520,13 +520,22 @@ class AmbientWeatherEntity(Entity):
|
||||
@callback
|
||||
def update():
|
||||
"""Update the state."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
self.update_from_latest_data()
|
||||
self.async_write_ha_state()
|
||||
|
||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||
self.hass, f"ambient_station_data_update_{self._mac_address}", update
|
||||
)
|
||||
|
||||
self.update_from_latest_data()
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
if self._async_unsub_dispatcher_connect:
|
||||
self._async_unsub_dispatcher_connect()
|
||||
self._async_unsub_dispatcher_connect = None
|
||||
|
||||
@callback
|
||||
def update_from_latest_data(self):
|
||||
"""Update the entity from the latest data."""
|
||||
raise NotImplementedError
|
||||
|
@ -3,6 +3,7 @@ import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.const import ATTR_NAME
|
||||
from homeassistant.core import callback
|
||||
|
||||
from . import (
|
||||
SENSOR_TYPES,
|
||||
@ -76,7 +77,8 @@ class AmbientWeatherBinarySensor(AmbientWeatherEntity, BinarySensorDevice):
|
||||
|
||||
return self._state == 1
|
||||
|
||||
async def async_update(self):
|
||||
@callback
|
||||
def update_from_latest_data(self):
|
||||
"""Fetch new state data for the entity."""
|
||||
self._state = self._ambient.stations[self._mac_address][ATTR_LAST_DATA].get(
|
||||
self._sensor_type
|
||||
|
@ -2,6 +2,7 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.const import ATTR_NAME
|
||||
from homeassistant.core import callback
|
||||
|
||||
from . import (
|
||||
SENSOR_TYPES,
|
||||
@ -74,7 +75,8 @@ class AmbientWeatherSensor(AmbientWeatherEntity):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
async def async_update(self):
|
||||
@callback
|
||||
def update_from_latest_data(self):
|
||||
"""Fetch new state data for the sensor."""
|
||||
if self._sensor_type == TYPE_SOLARRADIATION_LX:
|
||||
# If the user requests the solarradiation_lx sensor, use the
|
||||
|
Loading…
x
Reference in New Issue
Block a user