forked from mchwalisz/home-assistant-senec
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First implementation of spare capacity management (#19)
* First implementation of spare capacity management * -Enhancement of spare capacity management -Added information to readme.md -Added @io-debug to codeowners * updated readme.md
- Loading branch information
Showing
6 changed files
with
155 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Platform for Senec numbers.""" | ||
import logging | ||
|
||
from homeassistant.components.number import NumberEntity, NumberEntityDescription | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.helpers.typing import HomeAssistantType | ||
from homeassistant.util import slugify | ||
from homeassistant.const import CONF_TYPE | ||
|
||
from . import SenecDataUpdateCoordinator, SenecEntity | ||
from .const import ( | ||
DOMAIN, | ||
WEB_NUMBER_SENYOR_TYPES, | ||
CONF_SYSTYPE_WEB | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities): | ||
"""Initialize sensor platform from config entry.""" | ||
coordinator = hass.data[DOMAIN][config_entry.entry_id] | ||
entities = [] | ||
|
||
#Take care that CONF_TYPE = CONF_SYSTEYPE_WEB, since the implementation works with the web API | ||
if CONF_TYPE in config_entry.data and config_entry.data[CONF_TYPE] == CONF_SYSTYPE_WEB: | ||
for description in WEB_NUMBER_SENYOR_TYPES: | ||
entity = SenecNumber(coordinator, description) | ||
entities.append(entity) | ||
async_add_entities(entities) | ||
|
||
"""Implementation for the spare capacity of the senec device""" | ||
class SenecNumber(SenecEntity, NumberEntity): | ||
|
||
def __init__( | ||
self, | ||
coordinator: SenecDataUpdateCoordinator, | ||
description: NumberEntityDescription, | ||
): | ||
"""Initialize""" | ||
super().__init__(coordinator=coordinator, description=description) | ||
if (hasattr(self.entity_description, 'entity_registry_enabled_default')): | ||
self._attr_entity_registry_enabled_default = self.entity_description.entity_registry_enabled_default | ||
else: | ||
self._attr_entity_registry_enabled_default = True | ||
title = self.coordinator._config_entry.title | ||
key = self.entity_description.key | ||
name = self.entity_description.name | ||
self.entity_id = f"number.{slugify(title)}_{key}" | ||
self._attr_name = f"{title} {name}" | ||
|
||
@property | ||
def state(self) -> int: | ||
number = self.entity_description.key | ||
value = getattr(self.coordinator.senec, number) | ||
return int(value) | ||
|
||
async def async_set_native_value(self, value: int) -> None: | ||
"""Update the current value.""" | ||
updated_spare_capacity = int(value) | ||
api = self.coordinator.senec | ||
await api.set_spare_capacity(updated_spare_capacity) | ||
self.async_schedule_update_ha_state(force_refresh=True) | ||
|
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