-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move velux base entity to separate module (#126185)
- Loading branch information
Showing
5 changed files
with
43 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Support for VELUX KLF 200 devices.""" | ||
|
||
from pyvlx import Node | ||
|
||
from homeassistant.core import callback | ||
from homeassistant.helpers.entity import Entity | ||
|
||
|
||
class VeluxEntity(Entity): | ||
"""Abstraction for al Velux entities.""" | ||
|
||
_attr_should_poll = False | ||
|
||
def __init__(self, node: Node, config_entry_id: str) -> None: | ||
"""Initialize the Velux device.""" | ||
self.node = node | ||
self._attr_unique_id = ( | ||
node.serial_number | ||
if node.serial_number | ||
else f"{config_entry_id}_{node.node_id}" | ||
) | ||
self._attr_name = node.name if node.name else f"#{node.node_id}" | ||
|
||
@callback | ||
def async_register_callbacks(self): | ||
"""Register callbacks to update hass after device was changed.""" | ||
|
||
async def after_update_callback(device): | ||
"""Call after device was updated.""" | ||
self.async_write_ha_state() | ||
|
||
self.node.register_device_updated_cb(after_update_callback) | ||
|
||
async def async_added_to_hass(self): | ||
"""Store register state change callback.""" | ||
self.async_register_callbacks() |
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