From 05b5f16aa4e044fd29465033a1f451732cffbf47 Mon Sep 17 00:00:00 2001 From: BenPru <32298537+BenPru@users.noreply.github.com> Date: Wed, 25 Jan 2023 23:45:30 +0100 Subject: [PATCH] Add sensor and disable it Add sensor and disable it if luxtronik visibility is 0 --- custom_components/luxtronik/sensor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/luxtronik/sensor.py b/custom_components/luxtronik/sensor.py index d484320..f441376 100644 --- a/custom_components/luxtronik/sensor.py +++ b/custom_components/luxtronik/sensor.py @@ -869,6 +869,9 @@ def __init__( self._attr_extra_state_attributes = { ATTR_EXTRA_STATE_ATTRIBUTE_LUXTRONIK_KEY: sensor_key } self._extra_attributes = extra_attributes + def disable_by_default(self): + self._attr_entity_registry_enabled_default = False + @property def icon(self): # -> str | None: """Return the icon to be used for this entity.""" @@ -1186,8 +1189,9 @@ def _schedule_immediate_update(self): self.async_schedule_update_ha_state(True) def add_sensor_if_active(luxtronik, entities, check_key: str, sensor: LuxtronikSensor): - if luxtronik.get_value(check_key) > 0: - entities += [sensor] + if luxtronik.get_value(check_key) <= 0: + sensor.disable_by_default() + entities += [sensor] def add_sensor_if_min_minor_version(luxtronik, entities, min_minor: int, sensor: LuxtronikSensor): if luxtronik.firmware_version_minor >= min_minor: