-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement translation keys, OhmeEntity base class and new unique IDs
- Loading branch information
Showing
11 changed files
with
264 additions
and
693 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,37 @@ | ||
from homeassistant.helpers.entity import Entity | ||
from homeassistant.core import callback | ||
|
||
class OhmeEntity(Entity): | ||
"""Base class for all Ohme entities.""" | ||
|
||
_attr_has_entity_name = True | ||
|
||
def __init__(self, cooordinator, hass, client): | ||
"""Initialize the entity.""" | ||
self.coordinator = cooordinator | ||
self._hass = hass | ||
self._client = client | ||
|
||
self._attributes = {} | ||
self._last_updated = None | ||
self._state = None | ||
|
||
self._attr_device_info = client.get_device_info() | ||
|
||
async def async_added_to_hass(self) -> None: | ||
"""When entity is added to hass.""" | ||
await super().async_added_to_hass() | ||
self.async_on_remove( | ||
self.coordinator.async_add_listener( | ||
self._handle_coordinator_update, None | ||
) | ||
) | ||
|
||
@callback | ||
def _handle_coordinator_update(self) -> None: | ||
self.async_write_ha_state() | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return unique ID of the entity.""" | ||
return f"{self._client.serial}_{self._attr_translation_key}" |
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.