mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Fix lookin push updates when sensor entities disabled (#58346)
This commit is contained in:
parent
0600a21e02
commit
2a6247cf20
@ -5,11 +5,17 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiolookin import LookInHttpProtocol, LookinUDPSubscriptions, start_lookin_udp
|
from aiolookin import (
|
||||||
|
LookInHttpProtocol,
|
||||||
|
LookinUDPSubscriptions,
|
||||||
|
MeteoSensor,
|
||||||
|
SensorID,
|
||||||
|
start_lookin_udp,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
@ -45,7 +51,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
await meteo_coordinator.async_config_entry_first_refresh()
|
await meteo_coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_meteo_push_update(msg: dict[str, str]) -> None:
|
||||||
|
"""Process an update pushed via UDP."""
|
||||||
|
if int(msg["event_id"]):
|
||||||
|
return
|
||||||
|
LOGGER.debug("Processing push message for meteo sensor: %s", msg)
|
||||||
|
meteo: MeteoSensor = meteo_coordinator.data
|
||||||
|
meteo.update_from_value(msg["value"])
|
||||||
|
meteo_coordinator.async_set_updated_data(meteo)
|
||||||
|
|
||||||
lookin_udp_subs = LookinUDPSubscriptions()
|
lookin_udp_subs = LookinUDPSubscriptions()
|
||||||
|
entry.async_on_unload(
|
||||||
|
lookin_udp_subs.subscribe_sensor(
|
||||||
|
lookin_device.id, SensorID.Meteo, None, _async_meteo_push_update
|
||||||
|
)
|
||||||
|
)
|
||||||
entry.async_on_unload(await start_lookin_udp(lookin_udp_subs))
|
entry.async_on_unload(await start_lookin_udp(lookin_udp_subs))
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = LookinData(
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = LookinData(
|
||||||
|
@ -3,8 +3,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiolookin import MeteoSensor, SensorID
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
DEVICE_CLASS_HUMIDITY,
|
DEVICE_CLASS_HUMIDITY,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
@ -14,7 +12,7 @@ from homeassistant.components.sensor import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -74,22 +72,3 @@ class LookinSensorEntity(LookinDeviceCoordinatorEntity, SensorEntity):
|
|||||||
self.coordinator.data, self.entity_description.key
|
self.coordinator.data, self.entity_description.key
|
||||||
)
|
)
|
||||||
super()._handle_coordinator_update()
|
super()._handle_coordinator_update()
|
||||||
|
|
||||||
@callback
|
|
||||||
def _async_push_update(self, msg: dict[str, str]) -> None:
|
|
||||||
"""Process an update pushed via UDP."""
|
|
||||||
if int(msg["event_id"]):
|
|
||||||
return
|
|
||||||
LOGGER.debug("Processing push message for meteo sensor: %s", msg)
|
|
||||||
meteo: MeteoSensor = self.coordinator.data
|
|
||||||
meteo.update_from_value(msg["value"])
|
|
||||||
self.coordinator.async_set_updated_data(meteo)
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
|
||||||
"""Call when the entity is added to hass."""
|
|
||||||
self.async_on_remove(
|
|
||||||
self._lookin_udp_subs.subscribe_sensor(
|
|
||||||
self._lookin_device.id, SensorID.Meteo, None, self._async_push_update
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return await super().async_added_to_hass()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user