diff --git a/homeassistant/components/plugwise/number.py b/homeassistant/components/plugwise/number.py index 1f12b2374b3..06db5faa55b 100644 --- a/homeassistant/components/plugwise/number.py +++ b/homeassistant/components/plugwise/number.py @@ -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() diff --git a/tests/components/plugwise/test_number.py b/tests/components/plugwise/test_number.py index 8d49d07b9fb..e10a7caa9e9 100644 --- a/tests/components/plugwise/test_number.py +++ b/tests/components/plugwise/test_number.py @@ -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 )