Skip to content

Commit

Permalink
Attribute cleanup part 2 (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
brg468 authored Mar 19, 2024
1 parent 1357f91 commit 5205f6b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 70 deletions.
2 changes: 0 additions & 2 deletions custom_components/wyzeapi/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions custom_components/wyzeapi/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 7 additions & 11 deletions custom_components/wyzeapi/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
"""
Expand Down
32 changes: 14 additions & 18 deletions custom_components/wyzeapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions custom_components/wyzeapi/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions custom_components/wyzeapi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
}

Expand All @@ -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}",
}

Expand Down Expand Up @@ -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"
}

Expand All @@ -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",
}

Expand Down
11 changes: 0 additions & 11 deletions custom_components/wyzeapi/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 8 additions & 17 deletions custom_components/wyzeapi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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") + "%")
Expand Down

0 comments on commit 5205f6b

Please sign in to comment.