Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions homeassistant/components/homematicip_cloud/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@
ATTR_RSSI_PEER = "rssi_peer"
ATTR_SABOTAGE = "sabotage"
ATTR_GROUP_MEMBER_UNREACHABLE = "group_member_unreachable"
ATTR_DEVICE_OVERHEATED = "device_overheated"
ATTR_DEVICE_OVERLOADED = "device_overloaded"
ATTR_DEVICE_UNTERVOLTAGE = "device_undervoltage"

DEVICE_ATTRIBUTE_ICONS = {
"lowBat": "mdi:battery-outline",
"sabotage": "mdi:alert",
"deviceOverheated": "mdi:alert",
"deviceOverloaded": "mdi:alert",
"deviceUndervoltage": "mdi:alert",
}

DEVICE_ATTRIBUTES = {
"modelType": ATTR_MODEL_TYPE,
"id": ATTR_ID,
"sabotage": ATTR_SABOTAGE,
"rssiDeviceValue": ATTR_RSSI_DEVICE,
"rssiPeerValue": ATTR_RSSI_PEER,
"deviceOverheated": ATTR_DEVICE_OVERHEATED,
"deviceOverloaded": ATTR_DEVICE_OVERLOADED,
"deviceUndervoltage": ATTR_DEVICE_UNTERVOLTAGE,
}


class HomematicipGenericDevice(Entity):
Expand Down Expand Up @@ -85,21 +107,19 @@ def unique_id(self) -> str:
@property
def icon(self) -> Optional[str]:
"""Return the icon."""
if hasattr(self._device, "lowBat") and self._device.lowBat:
return "mdi:battery-outline"
if hasattr(self._device, "sabotage") and self._device.sabotage:
return "mdi:alert"
for attr, icon in DEVICE_ATTRIBUTE_ICONS.items():
if getattr(self._device, attr, None):
return icon

return None

@property
def device_state_attributes(self):
"""Return the state attributes of the generic device."""
attr = {ATTR_MODEL_TYPE: self._device.modelType, ATTR_ID: self._device.id}

if hasattr(self._device, "sabotage") and self._device.sabotage:
attr[ATTR_SABOTAGE] = self._device.sabotage
if hasattr(self._device, "rssiDeviceValue") and self._device.rssiDeviceValue:
attr[ATTR_RSSI_DEVICE] = self._device.rssiDeviceValue
if hasattr(self._device, "rssiPeerValue") and self._device.rssiPeerValue:
attr[ATTR_RSSI_PEER] = self._device.rssiPeerValue
return attr
state_attr = {}
for attr, attr_key in DEVICE_ATTRIBUTES.items():
attr_value = getattr(self._device, attr, None)
if attr_value:
state_attr[attr_key] = attr_value

return state_attr