From 5205f6b498247b7b2d4d867311df70f210777bc1 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Tue, 19 Mar 2024 16:11:40 -0400 Subject: [PATCH] Attribute cleanup part 2 (#553) --- .../wyzeapi/alarm_control_panel.py | 2 -- custom_components/wyzeapi/binary_sensor.py | 4 --- custom_components/wyzeapi/climate.py | 18 ++++------- custom_components/wyzeapi/light.py | 32 ++++++++----------- custom_components/wyzeapi/lock.py | 11 ++++--- custom_components/wyzeapi/sensor.py | 17 ++++++++-- custom_components/wyzeapi/siren.py | 11 ------- custom_components/wyzeapi/switch.py | 25 +++++---------- 8 files changed, 50 insertions(+), 70 deletions(-) diff --git a/custom_components/wyzeapi/alarm_control_panel.py b/custom_components/wyzeapi/alarm_control_panel.py index 734857cd..713599c9 100644 --- a/custom_components/wyzeapi/alarm_control_panel.py +++ b/custom_components/wyzeapi/alarm_control_panel.py @@ -128,8 +128,6 @@ def extra_state_attributes(self): """Return device attributes of the entity.""" return { ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.state, - "available": self.AVAILABLE, "device model": self.DEVICE_MODEL, "mac": self.unique_id } diff --git a/custom_components/wyzeapi/binary_sensor.py b/custom_components/wyzeapi/binary_sensor.py index a8d4e94c..8ca7807f 100644 --- a/custom_components/wyzeapi/binary_sensor.py +++ b/custom_components/wyzeapi/binary_sensor.py @@ -115,8 +115,6 @@ def extra_state_attributes(self): """Return device attributes of the entity.""" return { ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, "device model": self._sensor.product_model, "mac": self.unique_id } @@ -182,8 +180,6 @@ def extra_state_attributes(self): """Return device attributes of the entity.""" return { ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, "device model": self._camera.product_model, "mac": self.unique_id } diff --git a/custom_components/wyzeapi/climate.py b/custom_components/wyzeapi/climate.py index dab9584a..e837e7be 100644 --- a/custom_components/wyzeapi/climate.py +++ b/custom_components/wyzeapi/climate.py @@ -20,6 +20,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_ATTRIBUTION, UnitOfTemperature from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import device_registry as dr from wyzeapy import Wyzeapy, ThermostatService from wyzeapy.services.thermostat_service import Thermostat, TemperatureUnit, HVACMode, Preset, FanMode, HVACState from .token_manager import token_exception_handler @@ -266,6 +267,12 @@ def device_info(self) -> dict: "identifiers": { (DOMAIN, self._thermostat.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._thermostat.mac, + ) + }, "name": self.name, "manufacturer": "WyzeLabs", "model": self._thermostat.product_model @@ -289,17 +296,6 @@ def available(self) -> bool: """Return the connection status of this light""" return self._thermostat.available - @property - def extra_state_attributes(self): - """Return device attributes of the entity.""" - return { - ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.state, - "available": self.available, - "device_model": self._thermostat.product_model, - "mac": self.unique_id - } - @token_exception_handler async def async_update(self) -> None: """ diff --git a/custom_components/wyzeapi/light.py b/custom_components/wyzeapi/light.py index f5bae9bf..531e57c4 100644 --- a/custom_components/wyzeapi/light.py +++ b/custom_components/wyzeapi/light.py @@ -20,6 +20,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import device_registry as dr from wyzeapy import Wyzeapy, BulbService, CameraService from wyzeapy.services.bulb_service import Bulb from wyzeapy.types import DeviceTypes, PropertyIDs @@ -102,6 +103,12 @@ def device_info(self): "identifiers": { (DOMAIN, self._bulb.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._bulb.mac, + ) + }, "name": self.name, "manufacturer": "WyzeLabs", "model": self._bulb.product_model @@ -239,13 +246,7 @@ def hs_color(self): @property def extra_state_attributes(self): """Return device attributes of the entity.""" - dev_info = { - ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, - "device_model": self._bulb.product_model, - "mac": self.unique_id - } + dev_info = {} # noinspection DuplicatedCode if self._bulb.device_params.get("ip"): @@ -403,23 +404,18 @@ def name(self) -> str: def unique_id(self): return f"{self._device.mac}-floodlight" - @property - def extra_state_attributes(self): - """Return device attributes of the entity.""" - return { - ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, - "device model": f"{self._device.product_model}.floodlight", - "mac": self.unique_id - } - @property def device_info(self): return { "identifiers": { (DOMAIN, self._device.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._device.mac, + ) + }, "name": self.name, "manufacturer": "WyzeLabs", "model": self._device.product_model diff --git a/custom_components/wyzeapi/lock.py b/custom_components/wyzeapi/lock.py index 3750cb94..869308bd 100644 --- a/custom_components/wyzeapi/lock.py +++ b/custom_components/wyzeapi/lock.py @@ -15,6 +15,7 @@ from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers import device_registry as dr from .const import CONF_CLIENT, DOMAIN, LOCK_UPDATED from .token_manager import token_exception_handler @@ -67,6 +68,12 @@ def device_info(self): "identifiers": { (DOMAIN, self._lock.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._lock.mac, + ) + }, "name": self.name, "manufacturer": "WyzeLabs", "model": self._lock.product_model @@ -120,11 +127,7 @@ def extra_state_attributes(self): """Return device attributes of the entity.""" dev_info = { ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.state, - "available": self.available, "door_open": self._lock.door_open, - "device_model": self._lock.product_model, - "mac": self.unique_id } # Add the lock battery value if it exists diff --git a/custom_components/wyzeapi/sensor.py b/custom_components/wyzeapi/sensor.py index 080fb06f..132b9c72 100644 --- a/custom_components/wyzeapi/sensor.py +++ b/custom_components/wyzeapi/sensor.py @@ -14,6 +14,7 @@ from homeassistant.const import ATTR_ATTRIBUTION, PERCENTAGE from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers import device_registry as dr from .const import CONF_CLIENT, DOMAIN, LOCK_UPDATED, CAMERA_UPDATED from .token_manager import token_exception_handler @@ -68,7 +69,7 @@ def enabled(self): _attr_device_class = SensorDeviceClass.BATTERY _attr_native_unit_of_measurement = PERCENTAGE - + def __init__(self, lock, battery_type): self._enabled = None @@ -134,6 +135,12 @@ def device_info(self): "identifiers": { (DOMAIN, self._lock.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._lock.mac, + ) + }, "name": f"{self._lock.nickname}.{self._battery_type}" } @@ -142,7 +149,6 @@ def extra_state_attributes(self): """Return device attributes of the entity.""" return { ATTR_ATTRIBUTION: ATTRIBUTION, - "available": self.available, "device model": f"{self._lock.product_model}.{self._battery_type}", } @@ -200,6 +206,12 @@ def device_info(self): "identifiers": { (DOMAIN, self._camera.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._camera.mac, + ) + }, "name": f"{self._camera.nickname}.battery" } @@ -208,7 +220,6 @@ def extra_state_attributes(self): """Return device attributes of the entity.""" return { ATTR_ATTRIBUTION: ATTRIBUTION, - "available": self.available, "device model": f"{self._camera.product_model}.battery", } diff --git a/custom_components/wyzeapi/siren.py b/custom_components/wyzeapi/siren.py index df96dca5..a63f59a9 100644 --- a/custom_components/wyzeapi/siren.py +++ b/custom_components/wyzeapi/siren.py @@ -100,17 +100,6 @@ def name(self) -> str: def unique_id(self): return f"{self._device.mac}-siren" - @property - def extra_state_attributes(self): - """Return device attributes of the entity.""" - return { - ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, - "device model": f"{self._device.product_model}.siren", - "mac": self.unique_id - } - @property def device_info(self): return { diff --git a/custom_components/wyzeapi/switch.py b/custom_components/wyzeapi/switch.py index 9323648d..90624a9f 100644 --- a/custom_components/wyzeapi/switch.py +++ b/custom_components/wyzeapi/switch.py @@ -11,6 +11,7 @@ from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_send, async_dispatcher_connect +from homeassistant.helpers import device_registry as dr from wyzeapy import CameraService, SwitchService, WallSwitchService, Wyzeapy, BulbService from wyzeapy.services.camera_service import Camera from wyzeapy.services.switch_service import Switch @@ -136,16 +137,6 @@ def available(self): def unique_id(self): return self._uid - @property - def extra_state_attributes(self): - """Return device attributes of the entity.""" - return { - ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, - "mac": self.unique_id - } - async def async_update(self): if not self._just_updated: self._is_on = await self._client.notifications_are_on @@ -183,6 +174,12 @@ def device_info(self): "identifiers": { (DOMAIN, self._device.mac) }, + "connections": { + ( + dr.CONNECTION_NETWORK_MAC, + self._device.mac, + ) + }, "name": self._device.nickname, "manufacturer": "WyzeLabs", "model": self._device.product_model @@ -233,13 +230,7 @@ def unique_id(self): @property def extra_state_attributes(self): """Return device attributes of the entity.""" - dev_info = { - ATTR_ATTRIBUTION: ATTRIBUTION, - "state": self.is_on, - "available": self.available, - "device model": self._device.product_model, - "mac": self.unique_id - } + dev_info = {} if self._device.device_params.get("electricity"): dev_info["Battery"] = str(self._device.device_params.get("electricity") + "%")