Use entity class attributes for anel_pwrctrl (#52594)

* Use entity class attributes for anel_pwrctrl

* Tweak
pull/52701/head
Robert Hillis 2021-07-07 22:12:17 -04:00 committed by GitHub
parent b5a6d05778
commit 4e848f60c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 15 deletions

View File

@ -65,25 +65,13 @@ class PwrCtrlSwitch(SwitchEntity):
"""Initialize the PwrCtrl switch."""
self._port = port
self._parent_device = parent_device
@property
def unique_id(self):
"""Return the unique ID of the device."""
return f"{self._port.device.host}-{self._port.get_index()}"
@property
def name(self):
"""Return the name of the device."""
return self._port.label
@property
def is_on(self):
"""Return true if the device is on."""
return self._port.get_state()
self._attr_unique_id = f"{port.device.host}-{port.get_index()}"
self._attr_name = port.label
def update(self):
"""Trigger update for all switches on the parent device."""
self._parent_device.update()
self._attr_is_on = self._port.get_state()
def turn_on(self, **kwargs):
"""Turn the switch on."""