Change fix property to _attr for tradfri (#55691)

This commit is contained in:
jan iversen 2021-09-06 08:49:00 +02:00 committed by GitHub
parent 1b3530a3f8
commit 0dd128af77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 64 deletions

View file

@ -32,6 +32,8 @@ class TradfriBaseClass(Entity):
All devices and groups should ultimately inherit from this class.
"""
_attr_should_poll = False
def __init__(self, device, api, gateway_id):
"""Initialize a device."""
self._api = handle_error(api)
@ -39,9 +41,6 @@ class TradfriBaseClass(Entity):
self._device_control = None
self._device_data = None
self._gateway_id = gateway_id
self._name = None
self._unique_id = None
self._refresh(device)
@callback
@ -49,7 +48,7 @@ class TradfriBaseClass(Entity):
"""Start observation of device."""
if exc:
self.async_write_ha_state()
_LOGGER.warning("Observation failed for %s", self._name, exc_info=exc)
_LOGGER.warning("Observation failed for %s", self._attr_name, exc_info=exc)
try:
cmd = self._device.observe(
@ -66,21 +65,6 @@ class TradfriBaseClass(Entity):
"""Start thread when added to hass."""
self._async_start_observe()
@property
def name(self):
"""Return the display name of this device."""
return self._name
@property
def should_poll(self):
"""No polling needed for tradfri device."""
return False
@property
def unique_id(self):
"""Return unique ID for device."""
return self._unique_id
@callback
def _observe_update(self, device):
"""Receive new state data for this device."""
@ -90,7 +74,7 @@ class TradfriBaseClass(Entity):
def _refresh(self, device):
"""Refresh the device data."""
self._device = device
self._name = device.name
self._attr_name = device.name
class TradfriBaseDevice(TradfriBaseClass):
@ -99,16 +83,6 @@ class TradfriBaseDevice(TradfriBaseClass):
All devices should inherit from this class.
"""
def __init__(self, device, api, gateway_id):
"""Initialize a device."""
super().__init__(device, api, gateway_id)
self._available = True
@property
def available(self):
"""Return True if entity is available."""
return self._available
@property
def device_info(self):
"""Return the device info."""
@ -118,7 +92,7 @@ class TradfriBaseDevice(TradfriBaseClass):
"identifiers": {(DOMAIN, self._device.id)},
"manufacturer": info.manufacturer,
"model": info.model_number,
"name": self._name,
"name": self._attr_name,
"sw_version": info.firmware_version,
"via_device": (DOMAIN, self._gateway_id),
}
@ -126,4 +100,4 @@ class TradfriBaseDevice(TradfriBaseClass):
def _refresh(self, device):
"""Refresh the device data."""
super()._refresh(device)
self._available = device.reachable
self._attr_available = device.reachable

View file

@ -24,7 +24,7 @@ class TradfriCover(TradfriBaseDevice, CoverEntity):
def __init__(self, device, api, gateway_id):
"""Initialize a cover."""
super().__init__(device, api, gateway_id)
self._unique_id = f"{gateway_id}-{device.id}"
self._attr_unique_id = f"{gateway_id}-{device.id}"
self._refresh(device)

View file

@ -48,19 +48,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class TradfriGroup(TradfriBaseClass, LightEntity):
"""The platform class for light groups required by hass."""
_attr_supported_features = SUPPORTED_GROUP_FEATURES
def __init__(self, device, api, gateway_id):
"""Initialize a Group."""
super().__init__(device, api, gateway_id)
self._unique_id = f"group-{gateway_id}-{device.id}"
self._attr_unique_id = f"group-{gateway_id}-{device.id}"
self._attr_should_poll = True
self._refresh(device)
@property
def should_poll(self):
"""Poll needed for tradfri groups."""
return True
async def async_update(self):
"""Fetch new state data for the group.
@ -68,11 +65,6 @@ class TradfriGroup(TradfriBaseClass, LightEntity):
"""
await self._api(self._device.update())
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORTED_GROUP_FEATURES
@property
def is_on(self):
"""Return true if group lights are on."""
@ -108,7 +100,7 @@ class TradfriLight(TradfriBaseDevice, LightEntity):
def __init__(self, device, api, gateway_id):
"""Initialize a Light."""
super().__init__(device, api, gateway_id)
self._unique_id = f"light-{gateway_id}-{device.id}"
self._attr_unique_id = f"light-{gateway_id}-{device.id}"
self._hs_color = None
# Calculate supported features
@ -119,24 +111,11 @@ class TradfriLight(TradfriBaseDevice, LightEntity):
_features |= SUPPORT_COLOR | SUPPORT_COLOR_TEMP
if device.light_control.can_set_temp:
_features |= SUPPORT_COLOR_TEMP
self._features = _features
self._attr_supported_features = _features
self._refresh(device)
@property
def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
return self._device_control.min_mireds
@property
def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
return self._device_control.max_mireds
@property
def supported_features(self):
"""Flag supported features."""
return self._features
self._attr_min_mireds = self._device_control.min_mireds
self._attr_max_mireds = self._device_control.max_mireds
@property
def is_on(self):

View file

@ -35,7 +35,7 @@ class TradfriSensor(TradfriBaseDevice, SensorEntity):
def __init__(self, device, api, gateway_id):
"""Initialize the device."""
super().__init__(device, api, gateway_id)
self._unique_id = f"{gateway_id}-{device.id}"
self._attr_unique_id = f"{gateway_id}-{device.id}"
@property
def native_value(self):

View file

@ -25,7 +25,7 @@ class TradfriSwitch(TradfriBaseDevice, SwitchEntity):
def __init__(self, device, api, gateway_id):
"""Initialize a switch."""
super().__init__(device, api, gateway_id)
self._unique_id = f"{gateway_id}-{device.id}"
self._attr_unique_id = f"{gateway_id}-{device.id}"
def _refresh(self, device):
"""Refresh the switch data."""