Bump screenlogicpy to v0.10.0 (#104866)
This commit is contained in:
parent
6fd96f856d
commit
3b5e498c30
9 changed files with 58 additions and 54 deletions
|
@ -4,6 +4,7 @@ from collections.abc import Awaitable, Callable
|
|||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
from screenlogicpy.const.common import ScreenLogicCommunicationError, ScreenLogicError
|
||||
from screenlogicpy.const.data import ATTR, DEVICE, GROUP, VALUE
|
||||
from screenlogicpy.device_const.system import EQUIPMENT_FLAG
|
||||
|
||||
|
@ -15,6 +16,7 @@ from homeassistant.components.number import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN as SL_DOMAIN
|
||||
|
@ -32,7 +34,6 @@ class ScreenLogicNumberRequiredMixin:
|
|||
"""Describes a required mixin for a ScreenLogic number entity."""
|
||||
|
||||
set_value_name: str
|
||||
set_value_args: tuple[tuple[str | int, ...], ...]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -47,20 +48,12 @@ class ScreenLogicNumberDescription(
|
|||
SUPPORTED_SCG_NUMBERS = [
|
||||
ScreenLogicNumberDescription(
|
||||
set_value_name="async_set_scg_config",
|
||||
set_value_args=(
|
||||
(DEVICE.SCG, GROUP.CONFIGURATION, VALUE.POOL_SETPOINT),
|
||||
(DEVICE.SCG, GROUP.CONFIGURATION, VALUE.SPA_SETPOINT),
|
||||
),
|
||||
data_root=(DEVICE.SCG, GROUP.CONFIGURATION),
|
||||
key=VALUE.POOL_SETPOINT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
ScreenLogicNumberDescription(
|
||||
set_value_name="async_set_scg_config",
|
||||
set_value_args=(
|
||||
(DEVICE.SCG, GROUP.CONFIGURATION, VALUE.POOL_SETPOINT),
|
||||
(DEVICE.SCG, GROUP.CONFIGURATION, VALUE.SPA_SETPOINT),
|
||||
),
|
||||
data_root=(DEVICE.SCG, GROUP.CONFIGURATION),
|
||||
key=VALUE.SPA_SETPOINT,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
|
@ -113,7 +106,6 @@ class ScreenLogicNumber(ScreenlogicEntity, NumberEntity):
|
|||
f"set_value_name '{entity_description.set_value_name}' is not a coroutine"
|
||||
)
|
||||
self._set_value_func: Callable[..., Awaitable[bool]] = func
|
||||
self._set_value_args = entity_description.set_value_args
|
||||
self._attr_native_unit_of_measurement = get_ha_unit(
|
||||
self.entity_data.get(ATTR.UNIT)
|
||||
)
|
||||
|
@ -138,21 +130,14 @@ class ScreenLogicNumber(ScreenlogicEntity, NumberEntity):
|
|||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Update the current value."""
|
||||
|
||||
# Current API requires certain values to be set at the same time. This
|
||||
# gathers the existing values and updates the particular value being
|
||||
# set by this entity.
|
||||
args = {}
|
||||
for data_path in self._set_value_args:
|
||||
data_key = data_path[-1]
|
||||
args[data_key] = self.coordinator.gateway.get_value(*data_path, strict=True)
|
||||
|
||||
# Current API requires int values for the currently supported numbers.
|
||||
value = int(value)
|
||||
|
||||
args[self._data_key] = value
|
||||
|
||||
if await self._set_value_func(*args.values()):
|
||||
_LOGGER.debug("Set '%s' to %s", self._data_key, value)
|
||||
await self._async_refresh()
|
||||
else:
|
||||
_LOGGER.debug("Failed to set '%s' to %s", self._data_key, value)
|
||||
try:
|
||||
await self._set_value_func(**{self._data_key: value})
|
||||
except (ScreenLogicCommunicationError, ScreenLogicError) as sle:
|
||||
raise HomeAssistantError(
|
||||
f"Failed to set '{self._data_key}' to {value}: {sle.msg}"
|
||||
) from sle
|
||||
_LOGGER.debug("Set '%s' to %s", self._data_key, value)
|
||||
await self._async_refresh()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue