Migrate kostal_plenticore number to native_* (#74159)

pull/73834/head
Erik Montnemery 2022-06-29 10:04:22 +02:00 committed by GitHub
parent 20680535ec
commit 6a0ca2b36d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View File

@ -818,10 +818,10 @@ NUMBER_SETTINGS_DATA = [
entity_registry_enabled_default=False,
icon="mdi:battery-negative",
name="Battery min SoC",
unit_of_measurement=PERCENTAGE,
max_value=100,
min_value=5,
step=5,
native_unit_of_measurement=PERCENTAGE,
native_max_value=100,
native_min_value=5,
native_step=5,
module_id="devices:local",
data_id="Battery:MinSoc",
fmt_from="format_round",
@ -833,10 +833,10 @@ NUMBER_SETTINGS_DATA = [
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
name="Battery min Home Consumption",
unit_of_measurement=POWER_WATT,
max_value=38000,
min_value=50,
step=1,
native_unit_of_measurement=POWER_WATT,
native_max_value=38000,
native_min_value=50,
native_step=1,
module_id="devices:local",
data_id="Battery:MinHomeComsumption",
fmt_from="format_round",

View File

@ -105,9 +105,9 @@ class PlenticoreDataNumber(CoordinatorEntity, NumberEntity, ABC):
# overwrite from retrieved setting data
if setting_data.min is not None:
self._attr_min_value = self._formatter(setting_data.min)
self._attr_native_min_value = self._formatter(setting_data.min)
if setting_data.max is not None:
self._attr_max_value = self._formatter(setting_data.max)
self._attr_native_max_value = self._formatter(setting_data.max)
@property
def module_id(self) -> str:
@ -140,7 +140,7 @@ class PlenticoreDataNumber(CoordinatorEntity, NumberEntity, ABC):
await super().async_will_remove_from_hass()
@property
def value(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current value."""
if self.available:
raw_value = self.coordinator.data[self.module_id][self.data_id]
@ -148,7 +148,7 @@ class PlenticoreDataNumber(CoordinatorEntity, NumberEntity, ABC):
return None
async def async_set_value(self, value: float) -> None:
async def async_set_native_value(self, value: float) -> None:
"""Set a new value."""
str_value = self._formatter_back(value)
await self.coordinator.async_write_data(

View File

@ -31,8 +31,8 @@ def mock_number_description() -> PlenticoreNumberEntityDescription:
key="mock key",
module_id="moduleid",
data_id="dataid",
min_value=0,
max_value=1000,
native_min_value=0,
native_max_value=1000,
fmt_from="format_round",
fmt_to="format_round_back",
)
@ -136,7 +136,7 @@ async def test_set_value(
mock_coordinator, "42", "scb", None, mock_number_description, mock_setting_data
)
await entity.async_set_value(42)
await entity.async_set_native_value(42)
mock_coordinator.async_write_data.assert_called_once_with(
"moduleid", {"dataid": "42"}