mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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, "unregister_webhook", unregister_webhook)
|
||||
|
||||
entry.add_update_listener(async_config_entry_updated)
|
||||
|
||||
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):
|
||||
"""Unload a config entry."""
|
||||
if CONF_WEBHOOK_ID in entry.data:
|
||||
|
@ -95,12 +95,14 @@ class NetatmoDataHandler:
|
||||
for data_class in islice(self._queue, 0, BATCH_SIZE):
|
||||
if data_class[NEXT_SCAN] > time():
|
||||
continue
|
||||
self.data_classes[data_class["name"]][NEXT_SCAN] = (
|
||||
time() + data_class["interval"]
|
||||
)
|
||||
|
||||
if data_class_name := data_class["name"]:
|
||||
await self.async_fetch_data(data_class_name)
|
||||
self.data_classes[data_class_name][NEXT_SCAN] = (
|
||||
time() + data_class["interval"]
|
||||
)
|
||||
|
||||
if self.data_classes[data_class_name]["subscriptions"]:
|
||||
await self.async_fetch_data(data_class_name)
|
||||
|
||||
self._queue.rotate(BATCH_SIZE)
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
"""Base class for Netatmo entities."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, callback
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import DATA_DEVICE_IDS, DOMAIN, MANUFACTURER, MODELS, SIGNAL_NAME
|
||||
from .data_handler import PUBLICDATA_DATA_CLASS_NAME, NetatmoDataHandler
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NetatmoBase(Entity):
|
||||
"""Netatmo entity base class."""
|
||||
|
@ -2,7 +2,6 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_LATITUDE,
|
||||
ATTR_LONGITUDE,
|
||||
@ -21,7 +20,7 @@ from homeassistant.const import (
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.device_registry import async_entries_for_config_entry
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
@ -131,6 +130,7 @@ PUBLIC = "public"
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up the Netatmo weather and homecoach platform."""
|
||||
data_handler = hass.data[DOMAIN][entry.entry_id][DATA_HANDLER]
|
||||
platform_not_ready = False
|
||||
|
||||
async def find_entities(data_class_name):
|
||||
"""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)
|
||||
|
||||
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)
|
||||
|
||||
@ -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
|
||||
)
|
||||
|
||||
entry.add_update_listener(async_config_entry_updated)
|
||||
|
||||
await add_public_entities(False)
|
||||
|
||||
|
||||
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}")
|
||||
if platform_not_ready:
|
||||
raise PlatformNotReady
|
||||
|
||||
|
||||
class NetatmoSensor(NetatmoBase, SensorEntity):
|
||||
|
Loading…
x
Reference in New Issue
Block a user