Don't fetch data for disabled devices

This commit is contained in:
freybene 2024-05-29 15:27:53 +02:00
parent 8d68bbac4a
commit 9418cc61e6
2 changed files with 8 additions and 2 deletions

View file

@ -48,7 +48,7 @@ class DeviceBatterySensor(SensorEntity):
_LOGGER.info(f"battery sensor: tag_data none for '{self.name}'; rendering state unavailable") _LOGGER.info(f"battery sensor: tag_data none for '{self.name}'; rendering state unavailable")
return False return False
if not tag_data['update_success']: if not tag_data['update_success']:
_LOGGER.info(f"Last update for battery sensor'{self.name}' failed; rendering state unavailable") _LOGGER.info(f"Last update for battery sensor '{self.name}' failed; rendering state unavailable")
return False return False
return True return True

View file

@ -14,6 +14,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import device_registry
from .const import DOMAIN, BATTERY_LEVELS from .const import DOMAIN, BATTERY_LEVELS
@ -248,8 +249,13 @@ async def get_devices(hass: HomeAssistant, session: aiohttp.ClientSession) -> li
devices_data = response_json["deviceList"] devices_data = response_json["deviceList"]
devices = [] devices = []
for device in devices_data: for device in devices_data:
identifier = (DOMAIN, device['dvceID'])
ha_dev = device_registry.async_get(hass).async_get_device({identifier})
if ha_dev and ha_dev.disabled:
_LOGGER.debug(f"Ignoring disabled device: '{device['modelName']}' (disabled by {ha_dev.disabled_by})")
continue
ha_dev_info = DeviceInfo( ha_dev_info = DeviceInfo(
identifiers={(DOMAIN, device['dvceID'])}, identifiers={identifier},
manufacturer="Samsung", manufacturer="Samsung",
name=device['modelName'], name=device['modelName'],
model=device['modelID'], model=device['modelID'],