mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Fix Netatmo sensor initialization (#51195)
This commit is contained in:
parent
b6cb123c4f
commit
ac922916c1
@ -204,9 +204,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.services.async_register(DOMAIN, "register_webhook", register_webhook)
|
hass.services.async_register(DOMAIN, "register_webhook", register_webhook)
|
||||||
hass.services.async_register(DOMAIN, "unregister_webhook", unregister_webhook)
|
hass.services.async_register(DOMAIN, "unregister_webhook", unregister_webhook)
|
||||||
|
|
||||||
|
entry.add_update_listener(async_config_entry_updated)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def async_config_entry_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
|
"""Handle signals of config entry being updated."""
|
||||||
|
async_dispatcher_send(hass, f"signal-{DOMAIN}-public-update-{entry.entry_id}")
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if CONF_WEBHOOK_ID in entry.data:
|
if CONF_WEBHOOK_ID in entry.data:
|
||||||
|
@ -95,11 +95,13 @@ class NetatmoDataHandler:
|
|||||||
for data_class in islice(self._queue, 0, BATCH_SIZE):
|
for data_class in islice(self._queue, 0, BATCH_SIZE):
|
||||||
if data_class[NEXT_SCAN] > time():
|
if data_class[NEXT_SCAN] > time():
|
||||||
continue
|
continue
|
||||||
self.data_classes[data_class["name"]][NEXT_SCAN] = (
|
|
||||||
|
if data_class_name := data_class["name"]:
|
||||||
|
self.data_classes[data_class_name][NEXT_SCAN] = (
|
||||||
time() + data_class["interval"]
|
time() + data_class["interval"]
|
||||||
)
|
)
|
||||||
|
|
||||||
if data_class_name := data_class["name"]:
|
if self.data_classes[data_class_name]["subscriptions"]:
|
||||||
await self.async_fetch_data(data_class_name)
|
await self.async_fetch_data(data_class_name)
|
||||||
|
|
||||||
self._queue.rotate(BATCH_SIZE)
|
self._queue.rotate(BATCH_SIZE)
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
"""Base class for Netatmo entities."""
|
"""Base class for Netatmo entities."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.core import CALLBACK_TYPE, callback
|
from homeassistant.core import CALLBACK_TYPE, callback
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .const import DATA_DEVICE_IDS, DOMAIN, MANUFACTURER, MODELS, SIGNAL_NAME
|
from .const import DATA_DEVICE_IDS, DOMAIN, MANUFACTURER, MODELS, SIGNAL_NAME
|
||||||
from .data_handler import PUBLICDATA_DATA_CLASS_NAME, NetatmoDataHandler
|
from .data_handler import PUBLICDATA_DATA_CLASS_NAME, NetatmoDataHandler
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class NetatmoBase(Entity):
|
class NetatmoBase(Entity):
|
||||||
"""Netatmo entity base class."""
|
"""Netatmo entity base class."""
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_LATITUDE,
|
ATTR_LATITUDE,
|
||||||
ATTR_LONGITUDE,
|
ATTR_LONGITUDE,
|
||||||
@ -21,7 +20,7 @@ from homeassistant.const import (
|
|||||||
SPEED_KILOMETERS_PER_HOUR,
|
SPEED_KILOMETERS_PER_HOUR,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.device_registry import async_entries_for_config_entry
|
from homeassistant.helpers.device_registry import async_entries_for_config_entry
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -131,6 +130,7 @@ PUBLIC = "public"
|
|||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
"""Set up the Netatmo weather and homecoach platform."""
|
"""Set up the Netatmo weather and homecoach platform."""
|
||||||
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
||||||
|
platform_not_ready = False
|
||||||
|
|
||||||
async def find_entities(data_class_name):
|
async def find_entities(data_class_name):
|
||||||
"""Find all entities."""
|
"""Find all entities."""
|
||||||
@ -184,7 +184,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
data_class = data_handler.data.get(data_class_name)
|
data_class = data_handler.data.get(data_class_name)
|
||||||
|
|
||||||
if not data_class or not data_class.raw_data:
|
if not data_class or not data_class.raw_data:
|
||||||
raise PlatformNotReady
|
platform_not_ready = True
|
||||||
|
|
||||||
async_add_entities(await find_entities(data_class_name), True)
|
async_add_entities(await find_entities(data_class_name), True)
|
||||||
|
|
||||||
@ -241,14 +241,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
hass, f"signal-{DOMAIN}-public-update-{entry.entry_id}", add_public_entities
|
hass, f"signal-{DOMAIN}-public-update-{entry.entry_id}", add_public_entities
|
||||||
)
|
)
|
||||||
|
|
||||||
entry.add_update_listener(async_config_entry_updated)
|
|
||||||
|
|
||||||
await add_public_entities(False)
|
await add_public_entities(False)
|
||||||
|
|
||||||
|
if platform_not_ready:
|
||||||
async def async_config_entry_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
raise PlatformNotReady
|
||||||
"""Handle signals of config entry being updated."""
|
|
||||||
async_dispatcher_send(hass, f"signal-{DOMAIN}-public-update-{entry.entry_id}")
|
|
||||||
|
|
||||||
|
|
||||||
class NetatmoSensor(NetatmoBase, SensorEntity):
|
class NetatmoSensor(NetatmoBase, SensorEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user