Use entity class attributes for abode (#52427)

* Use entity class attributes for abode

* Apply suggestions from code review

Co-authored-by: Franck Nijhof <git@frenck.dev>

* move from base class

* fix

* Undo light supported features

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Robert Hillis 2021-07-05 04:31:11 -04:00 committed by GitHub
parent cacd803a93
commit 5321151799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 76 deletions

View file

@ -251,17 +251,13 @@ class AbodeEntity(Entity):
"""Initialize Abode entity."""
self._data = data
self._available = True
self._attr_should_poll = data.polling
@property
def available(self):
"""Return the available state."""
return self._available
@property
def should_poll(self):
"""Return the polling state."""
return self._data.polling
async def async_added_to_hass(self):
"""Subscribe to Abode connection status updates."""
await self.hass.async_add_executor_job(
@ -291,6 +287,8 @@ class AbodeDevice(AbodeEntity):
"""Initialize Abode device."""
super().__init__(data)
self._device = device
self._attr_name = device.name
self._attr_unique_id = device.device_uuid
async def async_added_to_hass(self):
"""Subscribe to device events."""
@ -312,11 +310,6 @@ class AbodeDevice(AbodeEntity):
"""Update device state."""
self._device.refresh()
@property
def name(self):
"""Return the name of the device."""
return self._device.name
@property
def extra_state_attributes(self):
"""Return the state attributes."""
@ -328,11 +321,6 @@ class AbodeDevice(AbodeEntity):
"device_type": self._device.type,
}
@property
def unique_id(self):
"""Return a unique ID to use for this device."""
return self._device.device_uuid
@property
def device_info(self):
"""Return device registry information for this entity."""
@ -355,22 +343,13 @@ class AbodeAutomation(AbodeEntity):
"""Initialize for Abode automation."""
super().__init__(data)
self._automation = automation
self._attr_name = automation.name
self._attr_unique_id = automation.automation_id
self._attr_extra_state_attributes = {
ATTR_ATTRIBUTION: ATTRIBUTION,
"type": "CUE automation",
}
def update(self):
"""Update automation state."""
self._automation.refresh()
@property
def name(self):
"""Return the name of the automation."""
return self._automation.name
@property
def extra_state_attributes(self):
"""Return the state attributes."""
return {ATTR_ATTRIBUTION: ATTRIBUTION, "type": "CUE automation"}
@property
def unique_id(self):
"""Return a unique ID to use for this automation."""
return self._automation.automation_id

View file

@ -28,10 +28,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
"""An alarm_control_panel implementation for Abode."""
@property
def icon(self):
"""Return the icon."""
return ICON
_attr_icon = ICON
_attr_code_arm_required = False
_attr_supported_features = SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
@property
def state(self):
@ -46,16 +45,6 @@ class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
state = None
return state
@property
def code_arm_required(self):
"""Whether the code is required for arm actions."""
return False
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
def alarm_disarm(self, code=None):
"""Send disarm command."""
self._device.set_standby()

View file

@ -41,23 +41,15 @@ class AbodeSensor(AbodeDevice, SensorEntity):
"""Initialize a sensor for an Abode device."""
super().__init__(data, device)
self._sensor_type = sensor_type
self._name = f"{self._device.name} {SENSOR_TYPES[self._sensor_type][0]}"
self._device_class = SENSOR_TYPES[self._sensor_type][1]
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def device_class(self):
"""Return the device class."""
return self._device_class
@property
def unique_id(self):
"""Return a unique ID to use for this device."""
return f"{self._device.device_uuid}-{self._sensor_type}"
self._attr_name = f"{device.name} {SENSOR_TYPES[sensor_type][0]}"
self._attr_device_class = SENSOR_TYPES[self._sensor_type][1]
self._attr_unique_id = f"{device.device_uuid}-{sensor_type}"
if self._sensor_type == CONST.TEMP_STATUS_KEY:
self._attr_unit_of_measurement = device.temp_unit
elif self._sensor_type == CONST.HUMI_STATUS_KEY:
self._attr_unit_of_measurement = device.humidity_unit
elif self._sensor_type == CONST.LUX_STATUS_KEY:
self._attr_unit_of_measurement = device.lux_unit
@property
def state(self):
@ -68,13 +60,3 @@ class AbodeSensor(AbodeDevice, SensorEntity):
return self._device.humidity
if self._sensor_type == CONST.LUX_STATUS_KEY:
return self._device.lux
@property
def unit_of_measurement(self):
"""Return the units of measurement."""
if self._sensor_type == CONST.TEMP_STATUS_KEY:
return self._device.temp_unit
if self._sensor_type == CONST.HUMI_STATUS_KEY:
return self._device.humidity_unit
if self._sensor_type == CONST.LUX_STATUS_KEY:
return self._device.lux_unit

View file

@ -48,6 +48,8 @@ class AbodeSwitch(AbodeDevice, SwitchEntity):
class AbodeAutomationSwitch(AbodeAutomation, SwitchEntity):
"""A switch implementation for Abode automations."""
_attr_icon = ICON
async def async_added_to_hass(self):
"""Set up trigger automation service."""
await super().async_added_to_hass()
@ -73,8 +75,3 @@ class AbodeAutomationSwitch(AbodeAutomation, SwitchEntity):
def is_on(self):
"""Return True if the automation is enabled."""
return self._automation.is_enabled
@property
def icon(self):
"""Return the robot icon to match Home Assistant automations."""
return ICON