Add unique ID to demo fan (#39658)

This commit is contained in:
Keilin Bickar 2020-09-04 12:23:53 -04:00 committed by GitHub
parent f1ee11cb14
commit 05e15dc318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,8 +18,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"""Set up the demo fan platform."""
async_add_entities(
[
DemoFan(hass, "Living Room Fan", FULL_SUPPORT),
DemoFan(hass, "Ceiling Fan", LIMITED_SUPPORT),
DemoFan(hass, "fan1", "Living Room Fan", FULL_SUPPORT),
DemoFan(hass, "fan2", "Ceiling Fan", LIMITED_SUPPORT),
]
)
@ -32,9 +32,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class DemoFan(FanEntity):
"""A demonstration fan component."""
def __init__(self, hass, name: str, supported_features: int) -> None:
def __init__(
self, hass, unique_id: str, name: str, supported_features: int
) -> None:
"""Initialize the entity."""
self.hass = hass
self._unique_id = unique_id
self._supported_features = supported_features
self._speed = STATE_OFF
self._oscillating = None
@ -46,6 +49,11 @@ class DemoFan(FanEntity):
if supported_features & SUPPORT_DIRECTION:
self._direction = "forward"
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id
@property
def name(self) -> str:
"""Get entity name."""