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 collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from plugwise import Smile
|
||||
|
||||
from homeassistant.components.number import (
|
||||
NumberDeviceClass,
|
||||
NumberEntity,
|
||||
|
@ -21,13 +18,13 @@ from . import PlugwiseConfigEntry
|
|||
from .const import NumberType
|
||||
from .coordinator import PlugwiseDataUpdateCoordinator
|
||||
from .entity import PlugwiseEntity
|
||||
from .util import plugwise_command
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class PlugwiseNumberEntityDescription(NumberEntityDescription):
|
||||
"""Class describing Plugwise Number entities."""
|
||||
|
||||
command: Callable[[Smile, str, str, float], Awaitable[None]]
|
||||
key: NumberType
|
||||
|
||||
|
||||
|
@ -35,9 +32,6 @@ NUMBER_TYPES = (
|
|||
PlugwiseNumberEntityDescription(
|
||||
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,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
|
@ -45,9 +39,6 @@ NUMBER_TYPES = (
|
|||
PlugwiseNumberEntityDescription(
|
||||
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,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
|
@ -55,9 +46,6 @@ NUMBER_TYPES = (
|
|||
PlugwiseNumberEntityDescription(
|
||||
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,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
|
@ -120,9 +108,9 @@ class PlugwiseNumberEntity(PlugwiseEntity, NumberEntity):
|
|||
"""Return the present setpoint value."""
|
||||
return self.device[self.entity_description.key]["setpoint"]
|
||||
|
||||
@plugwise_command
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Change to the new setpoint value."""
|
||||
await self.entity_description.command(
|
||||
self.coordinator.api, self.device_id, self.entity_description.key, value
|
||||
await self.coordinator.api.set_number(
|
||||
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,
|
||||
)
|
||||
|
||||
assert mock_smile_adam.set_temperature_offset.call_count == 1
|
||||
mock_smile_adam.set_temperature_offset.assert_called_with(
|
||||
"6a3bf693d05e48e0b460c815a4fdd09d", 1.0
|
||||
assert mock_smile_adam.set_number.call_count == 1
|
||||
mock_smile_adam.set_number.assert_called_with(
|
||||
"6a3bf693d05e48e0b460c815a4fdd09d", "temperature_offset", 1.0
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue