Implement @plugwise_command for Plugwise Number platform (#120503)
This commit is contained in:
parent
7b298f177c
commit
0a48cc29b6
2 changed files with 7 additions and 19 deletions
|
@ -2,11 +2,8 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from plugwise import Smile
|
|
||||||
|
|
||||||
from homeassistant.components.number import (
|
from homeassistant.components.number import (
|
||||||
NumberDeviceClass,
|
NumberDeviceClass,
|
||||||
NumberEntity,
|
NumberEntity,
|
||||||
|
@ -21,13 +18,13 @@ from . import PlugwiseConfigEntry
|
||||||
from .const import NumberType
|
from .const import NumberType
|
||||||
from .coordinator import PlugwiseDataUpdateCoordinator
|
from .coordinator import PlugwiseDataUpdateCoordinator
|
||||||
from .entity import PlugwiseEntity
|
from .entity import PlugwiseEntity
|
||||||
|
from .util import plugwise_command
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
class PlugwiseNumberEntityDescription(NumberEntityDescription):
|
class PlugwiseNumberEntityDescription(NumberEntityDescription):
|
||||||
"""Class describing Plugwise Number entities."""
|
"""Class describing Plugwise Number entities."""
|
||||||
|
|
||||||
command: Callable[[Smile, str, str, float], Awaitable[None]]
|
|
||||||
key: NumberType
|
key: NumberType
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,9 +32,6 @@ NUMBER_TYPES = (
|
||||||
PlugwiseNumberEntityDescription(
|
PlugwiseNumberEntityDescription(
|
||||||
key="maximum_boiler_temperature",
|
key="maximum_boiler_temperature",
|
||||||
translation_key="maximum_boiler_temperature",
|
translation_key="maximum_boiler_temperature",
|
||||||
command=lambda api, dev_id, number, value: api.set_number(
|
|
||||||
dev_id, number, value
|
|
||||||
),
|
|
||||||
device_class=NumberDeviceClass.TEMPERATURE,
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
@ -45,9 +39,6 @@ NUMBER_TYPES = (
|
||||||
PlugwiseNumberEntityDescription(
|
PlugwiseNumberEntityDescription(
|
||||||
key="max_dhw_temperature",
|
key="max_dhw_temperature",
|
||||||
translation_key="max_dhw_temperature",
|
translation_key="max_dhw_temperature",
|
||||||
command=lambda api, dev_id, number, value: api.set_number(
|
|
||||||
dev_id, number, value
|
|
||||||
),
|
|
||||||
device_class=NumberDeviceClass.TEMPERATURE,
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
@ -55,9 +46,6 @@ NUMBER_TYPES = (
|
||||||
PlugwiseNumberEntityDescription(
|
PlugwiseNumberEntityDescription(
|
||||||
key="temperature_offset",
|
key="temperature_offset",
|
||||||
translation_key="temperature_offset",
|
translation_key="temperature_offset",
|
||||||
command=lambda api, dev_id, number, value: api.set_temperature_offset(
|
|
||||||
dev_id, value
|
|
||||||
),
|
|
||||||
device_class=NumberDeviceClass.TEMPERATURE,
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
@ -120,9 +108,9 @@ class PlugwiseNumberEntity(PlugwiseEntity, NumberEntity):
|
||||||
"""Return the present setpoint value."""
|
"""Return the present setpoint value."""
|
||||||
return self.device[self.entity_description.key]["setpoint"]
|
return self.device[self.entity_description.key]["setpoint"]
|
||||||
|
|
||||||
|
@plugwise_command
|
||||||
async def async_set_native_value(self, value: float) -> None:
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
"""Change to the new setpoint value."""
|
"""Change to the new setpoint value."""
|
||||||
await self.entity_description.command(
|
await self.coordinator.api.set_number(
|
||||||
self.coordinator.api, self.device_id, self.entity_description.key, value
|
self.device_id, self.entity_description.key, value
|
||||||
)
|
)
|
||||||
await self.coordinator.async_request_refresh()
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ async def test_adam_temperature_offset_change(
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert mock_smile_adam.set_temperature_offset.call_count == 1
|
assert mock_smile_adam.set_number.call_count == 1
|
||||||
mock_smile_adam.set_temperature_offset.assert_called_with(
|
mock_smile_adam.set_number.assert_called_with(
|
||||||
"6a3bf693d05e48e0b460c815a4fdd09d", 1.0
|
"6a3bf693d05e48e0b460c815a4fdd09d", "temperature_offset", 1.0
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue