mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use entity class attributes for avion (#52696)
This commit is contained in:
parent
dabb50f7ee
commit
5b49107007
@ -65,49 +65,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class AvionLight(LightEntity):
|
class AvionLight(LightEntity):
|
||||||
"""Representation of an Avion light."""
|
"""Representation of an Avion light."""
|
||||||
|
|
||||||
|
_attr_supported_features = SUPPORT_AVION_LED
|
||||||
|
_attr_should_poll = False
|
||||||
|
_attr_assumed_state = True
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._name = device.name
|
self._attr_name = device.name
|
||||||
self._address = device.mac
|
self._attr_unique_id = device.mac
|
||||||
self._brightness = 255
|
self._attr_brightness = 255
|
||||||
self._state = False
|
|
||||||
self._switch = device
|
self._switch = device
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the ID of this light."""
|
|
||||||
return self._address
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device if any."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if device is on."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def brightness(self):
|
|
||||||
"""Return the brightness of this light between 0..255."""
|
|
||||||
return self._brightness
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Flag supported features."""
|
|
||||||
return SUPPORT_AVION_LED
|
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Don't poll."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
|
||||||
def assumed_state(self):
|
|
||||||
"""We can't read the actual state, so assume it matches."""
|
|
||||||
return True
|
|
||||||
|
|
||||||
def set_state(self, brightness):
|
def set_state(self, brightness):
|
||||||
"""Set the state of this lamp to the provided brightness."""
|
"""Set the state of this lamp to the provided brightness."""
|
||||||
avion = importlib.import_module("avion")
|
avion = importlib.import_module("avion")
|
||||||
@ -130,12 +98,12 @@ class AvionLight(LightEntity):
|
|||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
|
|
||||||
if brightness is not None:
|
if brightness is not None:
|
||||||
self._brightness = brightness
|
self._attr_brightness = brightness
|
||||||
|
|
||||||
self.set_state(self.brightness)
|
self.set_state(self.brightness)
|
||||||
self._state = True
|
self._attr_is_on = True
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the specified or all lights off."""
|
"""Turn the specified or all lights off."""
|
||||||
self.set_state(0)
|
self.set_state(0)
|
||||||
self._state = False
|
self._attr_is_on = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user