diff --git a/custom_components/mypyllant/__init__.py b/custom_components/mypyllant/__init__.py index 5571b96..0662a0a 100644 --- a/custom_components/mypyllant/__init__.py +++ b/custom_components/mypyllant/__init__.py @@ -81,17 +81,6 @@ def update_unique_id(entity_entry: RegistryEntry): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: - if _LOGGER.isEnabledFor(logging.DEBUG): - from importlib.metadata import version - - _LOGGER.debug( - "Starting mypyllant component %s (library %s) with homeassistant %s, pydantic %s, and aiohttp %s", - hass.data["integrations"][DOMAIN].version, - version("myPyllant"), - version("homeassistant"), - version("pydantic"), - version("aiohttp"), - ) username: str = entry.data.get("username") # type: ignore password: str = entry.data.get("password") # type: ignore update_interval = entry.options.get(OPTION_UPDATE_INTERVAL, DEFAULT_UPDATE_INTERVAL) diff --git a/custom_components/mypyllant/coordinator.py b/custom_components/mypyllant/coordinator.py index 21fc033..1756ab8 100644 --- a/custom_components/mypyllant/coordinator.py +++ b/custom_components/mypyllant/coordinator.py @@ -10,6 +10,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from homeassistant.helpers import entity_registry as er from custom_components.mypyllant.const import ( DOMAIN, @@ -204,6 +205,17 @@ class SystemWithDeviceData(TypedDict): class DailyDataCoordinator(MyPyllantCoordinator): data: dict[str, SystemWithDeviceData] + async def is_sensor_disabled(self, unique_id: str) -> bool: + """ + Check if a sensor is disabled to be able to skip its API update + """ + entity_registry = er.async_get(self.hass) + entity_id = entity_registry.async_get_entity_id("sensor", DOMAIN, unique_id) + if entity_id: + entity_entry = entity_registry.async_get(entity_id) + return entity_entry and entity_entry.disabled + return False + async def _async_update_data(self) -> dict[str, SystemWithDeviceData]: self._raise_if_quota_hit() _LOGGER.debug("Starting async update data for DailyDataCoordinator") @@ -227,7 +239,11 @@ async def _async_update_data(self) -> dict[str, SystemWithDeviceData]: "home_name": system.home.home_name or system.home.nomenclature, "devices_data": [], } - for device in system.devices: + for de_index, device in enumerate(system.devices): + for da_index, dd in enumerate(device.data): + sensor_id = f"{DOMAIN}_{device.system_id}_{device.device_uuid}_{da_index}_{de_index}" + if await self.is_sensor_disabled(sensor_id): + device.data[da_index].skip_data_update = True device_data = self.api.get_data_by_device( device, DeviceDataBucketResolution.HOUR, start, end ) diff --git a/custom_components/mypyllant/manifest.json b/custom_components/mypyllant/manifest.json index ab9d435..ab4e458 100644 --- a/custom_components/mypyllant/manifest.json +++ b/custom_components/mypyllant/manifest.json @@ -10,7 +10,7 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/signalkraft/mypyllant-component/issues", "requirements": [ - "myPyllant==0.8.33" + "myPyllant==0.8.36" ], "version": "v0.8.19" } diff --git a/custom_components/mypyllant/sensor.py b/custom_components/mypyllant/sensor.py index eeda1db..83edc5d 100644 --- a/custom_components/mypyllant/sensor.py +++ b/custom_components/mypyllant/sensor.py @@ -63,6 +63,7 @@ async def create_system_sensors( sensors: EntityList[SensorEntity] = EntityList() _LOGGER.debug("Creating system sensors for %s", system_coordinator.data) + sensors.append(lambda: SystemAPIRequestCount(system_coordinator)) for index, system in enumerate(system_coordinator.data): if system.outdoor_temperature is not None: sensors.append( @@ -858,7 +859,7 @@ def total_consumption(self) -> float | None: def unique_id(self) -> str | None: if self.device is None: return None - return f"{DOMAIN}_{self.system_id}_{self.device.device_uuid}_{self.da_index}" + return f"{DOMAIN}_{self.system_id}_{self.device.device_uuid}_{self.da_index}_{self.de_index}" @property def name_prefix(self) -> str: @@ -1109,3 +1110,19 @@ def unique_id(self) -> str: @property def name(self): return f"{self.name_prefix} Current Power" + + +class SystemAPIRequestCount(SensorEntity, CoordinatorEntity): + _attr_entity_category = EntityCategory.DIAGNOSTIC + + @property + def native_value(self): + return self.coordinator.api.aiohttp_session.request_count + + @property + def unique_id(self) -> str: + return f"{DOMAIN}_api_request_count" + + @property + def name(self): + return "Vaillant API Request Count" diff --git a/dev-requirements.txt b/dev-requirements.txt index b9c6397..7d00e6f 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -11,7 +11,7 @@ types-PyYAML~=6.0.12.20240311 # Need specific versions pytest-homeassistant-custom-component==0.13.142 -myPyllant==0.8.33 +myPyllant==0.8.36 # Versions handled by pytest-homeassistant-custom-component freezegun