generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add button to reset system warnings
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription | ||
from homeassistant.helpers.entity import EntityCategory | ||
from homeassistant.util import slugify | ||
from pysaleryd.const import DataKeyEnum | ||
|
||
from .const import CONF_ENABLE_INSTALLER_SETTINGS, SystemActiveModeEnum | ||
from .entity import SaleryLokeVirtualEntity | ||
|
||
if TYPE_CHECKING: | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .data import SalerydLokeConfigEntry | ||
|
||
|
||
class SalerydLokeButton(SaleryLokeVirtualEntity, ButtonEntity): | ||
def __init__(self, entry: "SalerydLokeConfigEntry", entity_description): | ||
self._entry = entry | ||
self.entity_id = f"button.{entry.unique_id}_{slugify(entity_description.name)}" | ||
super().__init__(entry, entity_description) | ||
|
||
|
||
class SalerydLokeSystemResetButton(SalerydLokeButton): | ||
async def async_press(self): | ||
await self._entry.runtime_data.bridge.send_command( | ||
DataKeyEnum.CONTROL_SYSTEM_STATE, SystemActiveModeEnum.Reset, True | ||
) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: "HomeAssistant", | ||
entry: "SalerydLokeConfigEntry", | ||
async_add_entities: "AddEntitiesCallback", | ||
): | ||
if entry.data.get(CONF_ENABLE_INSTALLER_SETTINGS): | ||
config_entities = [ | ||
SalerydLokeSystemResetButton( | ||
entry, | ||
ButtonEntityDescription( | ||
key=DataKeyEnum.CONTROL_SYSTEM_STATE, | ||
name="System reset", | ||
entity_category=EntityCategory.CONFIG, | ||
icon="mdi:restart", | ||
), | ||
) | ||
] | ||
async_add_entities(config_entities) |