From b1226920a27fd9dd86f3b52309f00b8fd7b9a49f Mon Sep 17 00:00:00 2001 From: Preston A Elder Date: Wed, 17 May 2023 02:11:54 -0400 Subject: [PATCH] Attempted to handle disabling some features from the get go. Unfortunately, it will actually disable stuff I DON'T want disabled. --- custom_components/powerpetdoor/number.py | 4 ++++ custom_components/powerpetdoor/sensor.py | 4 ++++ custom_components/powerpetdoor/switch.py | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/custom_components/powerpetdoor/number.py b/custom_components/powerpetdoor/number.py index aca500d..94fd72d 100644 --- a/custom_components/powerpetdoor/number.py +++ b/custom_components/powerpetdoor/number.py @@ -58,6 +58,7 @@ "class": NumberDeviceClass.VOLTAGE, "category": EntityCategory.CONFIG, "unit_of_measurement": UnitOfElectricPotential.VOLT, + "disabled": True, }, "sleep_sensor_trigger_voltage": { "field": FIELD_SLEEP_SENSOR_TRIGGER_VOLTAGE, @@ -68,6 +69,7 @@ "class": NumberDeviceClass.VOLTAGE, "category": EntityCategory.CONFIG, "unit_of_measurement": UnitOfElectricPotential.VOLT, + "disabled": True, }, } @@ -99,6 +101,8 @@ def __init__(self, self._attr_native_step = number["step"] if "unit" in number: self._attr_native_unit_of_measurement = number["unit"] + if "disabled" in number: + self._attr_entity_registry_visible_default = not number["disabled"] if "multiplier" in number: self.multiplier = number["multiplier"] self._attr_device_info = device diff --git a/custom_components/powerpetdoor/sensor.py b/custom_components/powerpetdoor/sensor.py index 3ff5e2b..2b32bf6 100644 --- a/custom_components/powerpetdoor/sensor.py +++ b/custom_components/powerpetdoor/sensor.py @@ -59,12 +59,14 @@ "icon": "mdi:reload", "class": "total_increasing", "category": EntityCategory.DIAGNOSTIC, + "disabled": True, }, "auto_retracts": { "field": FIELD_TOTAL_AUTO_RETRACTS, "icon": "mdi:alert", "class": "total_increasing", "category": EntityCategory.DIAGNOSTIC, + "disabled": True, }, } @@ -319,6 +321,8 @@ def __init__(self, self._attr_entity_category = sensor["category"] if "class" in sensor: self._attr_state_class = sensor["class"] + if "disabled" in sensor: + self._attr_entity_registry_visible_default = not sensor["disabled"] self._attr_device_info = device self._attr_unique_id = f"{client.host}:{client.port}-{sensor['field']}" diff --git a/custom_components/powerpetdoor/switch.py b/custom_components/powerpetdoor/switch.py index 38f018b..5067dc5 100644 --- a/custom_components/powerpetdoor/switch.py +++ b/custom_components/powerpetdoor/switch.py @@ -94,7 +94,8 @@ "disable": CMD_DISABLE_OUTSIDE_SENSOR_SAFETY_LOCK, "icon_on": "mdi:weather-sunny-alert", "icon_off": "mdi:shield-sun-outline", - "category": EntityCategory.CONFIG + "category": EntityCategory.CONFIG, + "disabled": True, }, "cmd_lockout": { "field": FIELD_CMD_LOCKOUT, @@ -103,7 +104,8 @@ "disable": CMD_DISABLE_CMD_LOCKOUT, "icon_on": "mdi:window-shutter-open", "icon_off": "mdi:window-shutter", - "category": EntityCategory.CONFIG + "category": EntityCategory.CONFIG, + "disabled": True, }, "autoretract": { "field": FIELD_AUTORETRACT, @@ -112,7 +114,8 @@ "disable": CMD_DISABLE_AUTORETRACT, "icon_on": "mdi:window-shutter-alert", "icon_off": "mdi:window-shutter-settings", - "category": EntityCategory.CONFIG + "category": EntityCategory.CONFIG, + "disabled": True, }, "power": { "field": FIELD_POWER, @@ -129,26 +132,31 @@ "field": FIELD_SENSOR_ON_INDOOR_NOTIFICATIONS, "icon_on": "mdi:motion-sensor", "icon_off": "mdi:motion-sensor-off", + "disabled": True, }, "inside_off": { "field": FIELD_SENSOR_OFF_INDOOR_NOTIFICATIONS, "icon_on": "mdi:motion-sensor", "icon_off": "mdi:motion-sensor-off", + "disabled": True, }, "outside_on": { "field": FIELD_SENSOR_ON_OUTDOOR_NOTIFICATIONS, "icon_on": "mdi:motion-sensor", "icon_off": "mdi:motion-sensor-off", + "disabled": True, }, "outside_off": { "field": FIELD_SENSOR_OFF_OUTDOOR_NOTIFICATIONS, "icon_on": "mdi:motion-sensor", "icon_off": "mdi:motion-sensor-off", + "disabled": True, }, "low_battery": { "field": FIELD_LOW_BATTERY_NOTIFICATIONS, "icon_on": "mdi:battery-alert-variant-outline", "icon_off": "mdi:battery-remove-outline", + "disabled": True, }, } @@ -170,6 +178,8 @@ def __init__(self, self._attr_name = name if "category" in switch: self._attr_entity_category = switch["category"] + if "disabled" in switch: + self._attr_entity_registry_visible_default = not switch["disabled"] self._attr_device_info = device self._attr_unique_id = f"{client.host}:{client.port}-{switch['field']}" @@ -244,6 +254,8 @@ def __init__(self, self.switch = switch self._attr_name = name + if "disabled" in switch: + self._attr_entity_registry_visible_default = not switch["disabled"] self._attr_device_info = device self._attr_unique_id = f"{client.host}:{client.port}-{switch['field']}"