mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
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:
parent
cacd803a93
commit
5321151799
@ -251,17 +251,13 @@ class AbodeEntity(Entity):
|
|||||||
"""Initialize Abode entity."""
|
"""Initialize Abode entity."""
|
||||||
self._data = data
|
self._data = data
|
||||||
self._available = True
|
self._available = True
|
||||||
|
self._attr_should_poll = data.polling
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return the available state."""
|
"""Return the available state."""
|
||||||
return self._available
|
return self._available
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return the polling state."""
|
|
||||||
return self._data.polling
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Subscribe to Abode connection status updates."""
|
"""Subscribe to Abode connection status updates."""
|
||||||
await self.hass.async_add_executor_job(
|
await self.hass.async_add_executor_job(
|
||||||
@ -291,6 +287,8 @@ class AbodeDevice(AbodeEntity):
|
|||||||
"""Initialize Abode device."""
|
"""Initialize Abode device."""
|
||||||
super().__init__(data)
|
super().__init__(data)
|
||||||
self._device = device
|
self._device = device
|
||||||
|
self._attr_name = device.name
|
||||||
|
self._attr_unique_id = device.device_uuid
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Subscribe to device events."""
|
"""Subscribe to device events."""
|
||||||
@ -312,11 +310,6 @@ class AbodeDevice(AbodeEntity):
|
|||||||
"""Update device state."""
|
"""Update device state."""
|
||||||
self._device.refresh()
|
self._device.refresh()
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return self._device.name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@ -328,11 +321,6 @@ class AbodeDevice(AbodeEntity):
|
|||||||
"device_type": self._device.type,
|
"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
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return device registry information for this entity."""
|
"""Return device registry information for this entity."""
|
||||||
@ -355,22 +343,13 @@ class AbodeAutomation(AbodeEntity):
|
|||||||
"""Initialize for Abode automation."""
|
"""Initialize for Abode automation."""
|
||||||
super().__init__(data)
|
super().__init__(data)
|
||||||
self._automation = automation
|
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):
|
def update(self):
|
||||||
"""Update automation state."""
|
"""Update automation state."""
|
||||||
self._automation.refresh()
|
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
|
|
||||||
|
@ -28,10 +28,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
|
class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
|
||||||
"""An alarm_control_panel implementation for Abode."""
|
"""An alarm_control_panel implementation for Abode."""
|
||||||
|
|
||||||
@property
|
_attr_icon = ICON
|
||||||
def icon(self):
|
_attr_code_arm_required = False
|
||||||
"""Return the icon."""
|
_attr_supported_features = SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
|
||||||
return ICON
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -46,16 +45,6 @@ class AbodeAlarm(AbodeDevice, alarm.AlarmControlPanelEntity):
|
|||||||
state = None
|
state = None
|
||||||
return state
|
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):
|
def alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
self._device.set_standby()
|
self._device.set_standby()
|
||||||
|
@ -41,23 +41,15 @@ class AbodeSensor(AbodeDevice, SensorEntity):
|
|||||||
"""Initialize a sensor for an Abode device."""
|
"""Initialize a sensor for an Abode device."""
|
||||||
super().__init__(data, device)
|
super().__init__(data, device)
|
||||||
self._sensor_type = sensor_type
|
self._sensor_type = sensor_type
|
||||||
self._name = f"{self._device.name} {SENSOR_TYPES[self._sensor_type][0]}"
|
self._attr_name = f"{device.name} {SENSOR_TYPES[sensor_type][0]}"
|
||||||
self._device_class = SENSOR_TYPES[self._sensor_type][1]
|
self._attr_device_class = SENSOR_TYPES[self._sensor_type][1]
|
||||||
|
self._attr_unique_id = f"{device.device_uuid}-{sensor_type}"
|
||||||
@property
|
if self._sensor_type == CONST.TEMP_STATUS_KEY:
|
||||||
def name(self):
|
self._attr_unit_of_measurement = device.temp_unit
|
||||||
"""Return the name of the sensor."""
|
elif self._sensor_type == CONST.HUMI_STATUS_KEY:
|
||||||
return self._name
|
self._attr_unit_of_measurement = device.humidity_unit
|
||||||
|
elif self._sensor_type == CONST.LUX_STATUS_KEY:
|
||||||
@property
|
self._attr_unit_of_measurement = device.lux_unit
|
||||||
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}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -68,13 +60,3 @@ class AbodeSensor(AbodeDevice, SensorEntity):
|
|||||||
return self._device.humidity
|
return self._device.humidity
|
||||||
if self._sensor_type == CONST.LUX_STATUS_KEY:
|
if self._sensor_type == CONST.LUX_STATUS_KEY:
|
||||||
return self._device.lux
|
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
|
|
||||||
|
@ -48,6 +48,8 @@ class AbodeSwitch(AbodeDevice, SwitchEntity):
|
|||||||
class AbodeAutomationSwitch(AbodeAutomation, SwitchEntity):
|
class AbodeAutomationSwitch(AbodeAutomation, SwitchEntity):
|
||||||
"""A switch implementation for Abode automations."""
|
"""A switch implementation for Abode automations."""
|
||||||
|
|
||||||
|
_attr_icon = ICON
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Set up trigger automation service."""
|
"""Set up trigger automation service."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
@ -73,8 +75,3 @@ class AbodeAutomationSwitch(AbodeAutomation, SwitchEntity):
|
|||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return True if the automation is enabled."""
|
"""Return True if the automation is enabled."""
|
||||||
return self._automation.is_enabled
|
return self._automation.is_enabled
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the robot icon to match Home Assistant automations."""
|
|
||||||
return ICON
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user