-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from tijsverkoyen/improvement-0612
Improvement 06/12
- Loading branch information
Showing
192 changed files
with
1,219 additions
and
2,854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 5 additions & 16 deletions
21
custom_components/nhc2/entities/accesscontrol_action_basicstate_switch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,27 @@ | ||
from homeassistant.components.switch import SwitchEntity | ||
|
||
from ..nhccoco.devices.accesscontrol_action import CocoAccesscontrolAction | ||
from .nhc_entity import NHCBaseEntity | ||
|
||
|
||
class Nhc2AccesscontrolActionBasicStateSwitchEntity(SwitchEntity): | ||
class Nhc2AccesscontrolActionBasicStateSwitchEntity(NHCBaseEntity, SwitchEntity): | ||
_attr_has_entity_name = True | ||
_attr_name = None | ||
|
||
def __init__(self, device_instance: CocoAccesscontrolAction, hub, gateway): | ||
"""Initialize a switch.""" | ||
self._device = device_instance | ||
self._hub = hub | ||
self._gateway = gateway | ||
|
||
self._device.after_change_callbacks.append(self.on_change) | ||
|
||
self._attr_available = self._device.is_online | ||
self._attr_unique_id = device_instance.uuid | ||
self._attr_should_poll = False | ||
self._attr_device_info = self._device.device_info(self._hub) | ||
super().__init__(device_instance, hub, gateway) | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
return self._device.is_basic_state_on | ||
|
||
def on_change(self): | ||
self.schedule_update_ha_state() | ||
|
||
async def async_turn_on(self): | ||
if not self.is_on: | ||
self._device.press(self._gateway) | ||
self.on_change() | ||
self.schedule_update_ha_state() | ||
|
||
async def async_turn_off(self): | ||
if self.is_on: | ||
self._device.press(self._gateway) | ||
self.on_change() | ||
self.schedule_update_ha_state() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.