From 1c4857aa5078ca1f0f3e5441d4c29b12e39855a6 Mon Sep 17 00:00:00 2001 From: Tijs Verkoyen Date: Tue, 28 Feb 2023 15:10:56 +0100 Subject: [PATCH] Implemented suggested_display_precision See https://developers.home-assistant.io/blog/2023/02/08/sensor_presentation_rounding/ for more information --- .../entities/electricity_clamp_centralmeter_electrical_power.py | 1 + ...lectricity_clamp_centralmeter_electrical_power_consumption.py | 1 + ...electricity_clamp_centralmeter_electrical_power_production.py | 1 + .../entities/generic_energyhome_electrical_power_consumption.py | 1 + .../entities/generic_energyhome_electrical_power_from_grid.py | 1 + .../entities/generic_energyhome_electrical_power_production.py | 1 + .../generic_energyhome_electrical_power_self_consumption.py | 1 + .../nhc2/entities/generic_energyhome_electrical_power_to_grid.py | 1 + custom_components/nhc2/entities/generic_fan_co2.py | 1 + custom_components/nhc2/entities/generic_fan_humidity.py | 1 + .../nhc2/entities/generic_smartplug_electrical_power.py | 1 + .../nhc2/entities/hvacthermostat_hvac_overrule_setpoint.py | 1 + .../nhc2/entities/hvacthermostat_hvac_setpoint_temperature.py | 1 + .../nhc2/entities/naso_smartplug_electrical_power.py | 1 + .../nhc2/entities/thermostat_hvac_overrule_setpoint.py | 1 + .../nhc2/entities/thermostat_hvac_setpoint_temperature.py | 1 + .../nhc2/entities/thermostat_thermostat_overrule_setpoint.py | 1 + .../nhc2/entities/thermostat_thermostat_setpoint_temperature.py | 1 + 18 files changed, 18 insertions(+) diff --git a/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power.py b/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power.py index 1d25a0c7..7ad2e648 100644 --- a/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power.py +++ b/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gatew self._attr_native_value = self._device.electrical_power self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_consumption.py b/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_consumption.py index a22f1d81..af8b262d 100644 --- a/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_consumption.py +++ b/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_consumption.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gatew self._attr_native_value = self._device.electrical_power self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_production.py b/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_production.py index 38002bb2..a8f22f3c 100644 --- a/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_production.py +++ b/custom_components/nhc2/entities/electricity_clamp_centralmeter_electrical_power_production.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoElectricityClampCentralmeter, hub, gatew self._attr_native_value = self._device.electrical_power self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_energyhome_electrical_power_consumption.py b/custom_components/nhc2/entities/generic_energyhome_electrical_power_consumption.py index 578a666a..73d975f9 100644 --- a/custom_components/nhc2/entities/generic_energyhome_electrical_power_consumption.py +++ b/custom_components/nhc2/entities/generic_energyhome_electrical_power_consumption.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway): self._attr_native_value = self._device.electrical_power_consumption self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 3 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_energyhome_electrical_power_from_grid.py b/custom_components/nhc2/entities/generic_energyhome_electrical_power_from_grid.py index 91e52c86..59b8815e 100644 --- a/custom_components/nhc2/entities/generic_energyhome_electrical_power_from_grid.py +++ b/custom_components/nhc2/entities/generic_energyhome_electrical_power_from_grid.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway): self._attr_native_value = self._device.electrical_power_from_grid self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 3 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_energyhome_electrical_power_production.py b/custom_components/nhc2/entities/generic_energyhome_electrical_power_production.py index b7fe5331..c56ef322 100644 --- a/custom_components/nhc2/entities/generic_energyhome_electrical_power_production.py +++ b/custom_components/nhc2/entities/generic_energyhome_electrical_power_production.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway): self._attr_native_value = self._device.electrical_power_production self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 3 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_energyhome_electrical_power_self_consumption.py b/custom_components/nhc2/entities/generic_energyhome_electrical_power_self_consumption.py index d50ad9df..4c5f3cfd 100644 --- a/custom_components/nhc2/entities/generic_energyhome_electrical_power_self_consumption.py +++ b/custom_components/nhc2/entities/generic_energyhome_electrical_power_self_consumption.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway): self._attr_native_value = self._device.electrical_power_self_consumption self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 3 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_energyhome_electrical_power_to_grid.py b/custom_components/nhc2/entities/generic_energyhome_electrical_power_to_grid.py index c9ac6bce..e5ee48a4 100644 --- a/custom_components/nhc2/entities/generic_energyhome_electrical_power_to_grid.py +++ b/custom_components/nhc2/entities/generic_energyhome_electrical_power_to_grid.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway): self._attr_native_value = self._device.electrical_power_to_grid self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 3 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_fan_co2.py b/custom_components/nhc2/entities/generic_fan_co2.py index b12a9df7..f4c9424c 100644 --- a/custom_components/nhc2/entities/generic_fan_co2.py +++ b/custom_components/nhc2/entities/generic_fan_co2.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericFan, hub, gateway): self._attr_native_value = self._device.co2 self._attr_native_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION self._attr_state_class = None + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_fan_humidity.py b/custom_components/nhc2/entities/generic_fan_humidity.py index 2f5fc6d2..84d94499 100644 --- a/custom_components/nhc2/entities/generic_fan_humidity.py +++ b/custom_components/nhc2/entities/generic_fan_humidity.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericFan, hub, gateway): self._attr_native_value = self._device.humidity self._attr_native_unit_of_measurement = PERCENTAGE self._attr_state_class = None + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/generic_smartplug_electrical_power.py b/custom_components/nhc2/entities/generic_smartplug_electrical_power.py index 4e2bb4ce..10488abf 100644 --- a/custom_components/nhc2/entities/generic_smartplug_electrical_power.py +++ b/custom_components/nhc2/entities/generic_smartplug_electrical_power.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoGenericSmartplug, hub, gateway): self._attr_native_value = self._device.electrical_power self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/hvacthermostat_hvac_overrule_setpoint.py b/custom_components/nhc2/entities/hvacthermostat_hvac_overrule_setpoint.py index a31e3ad1..47a6ac4e 100644 --- a/custom_components/nhc2/entities/hvacthermostat_hvac_overrule_setpoint.py +++ b/custom_components/nhc2/entities/hvacthermostat_hvac_overrule_setpoint.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoHvacthermostatHvac, hub, gateway): self._attr_native_value = self._device.overrule_setpoint self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_state_class = None + self._attr_suggested_display_precision = 1 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/hvacthermostat_hvac_setpoint_temperature.py b/custom_components/nhc2/entities/hvacthermostat_hvac_setpoint_temperature.py index f6916456..d47b723f 100644 --- a/custom_components/nhc2/entities/hvacthermostat_hvac_setpoint_temperature.py +++ b/custom_components/nhc2/entities/hvacthermostat_hvac_setpoint_temperature.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoHvacthermostatHvac, hub, gateway): self._attr_native_value = self._device.setpoint_temperature self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_state_class = None + self._attr_suggested_display_precision = 1 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/naso_smartplug_electrical_power.py b/custom_components/nhc2/entities/naso_smartplug_electrical_power.py index 4da01afd..e3a87482 100644 --- a/custom_components/nhc2/entities/naso_smartplug_electrical_power.py +++ b/custom_components/nhc2/entities/naso_smartplug_electrical_power.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoNasoSmartplug, hub, gateway): self._attr_native_value = self._device.electrical_power self._attr_native_unit_of_measurement = UnitOfPower.WATT self._attr_state_class = SensorStateClass.MEASUREMENT + self._attr_suggested_display_precision = 0 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/thermostat_hvac_overrule_setpoint.py b/custom_components/nhc2/entities/thermostat_hvac_overrule_setpoint.py index 0c02fef1..aa8199b8 100644 --- a/custom_components/nhc2/entities/thermostat_hvac_overrule_setpoint.py +++ b/custom_components/nhc2/entities/thermostat_hvac_overrule_setpoint.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoThermostatHvac, hub, gateway): self._attr_native_value = self._device.overrule_setpoint self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_state_class = None + self._attr_suggested_display_precision = 1 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/thermostat_hvac_setpoint_temperature.py b/custom_components/nhc2/entities/thermostat_hvac_setpoint_temperature.py index c9de039d..66cb9b66 100644 --- a/custom_components/nhc2/entities/thermostat_hvac_setpoint_temperature.py +++ b/custom_components/nhc2/entities/thermostat_hvac_setpoint_temperature.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoThermostatHvac, hub, gateway): self._attr_native_value = self._device.setpoint_temperature self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_state_class = None + self._attr_suggested_display_precision = 1 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/thermostat_thermostat_overrule_setpoint.py b/custom_components/nhc2/entities/thermostat_thermostat_overrule_setpoint.py index 21d78e56..3607ee16 100644 --- a/custom_components/nhc2/entities/thermostat_thermostat_overrule_setpoint.py +++ b/custom_components/nhc2/entities/thermostat_thermostat_overrule_setpoint.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoThermostatThermostat, hub, gateway): self._attr_native_value = self._device.overrule_setpoint self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_state_class = None + self._attr_suggested_display_precision = 1 @property def name(self) -> str: diff --git a/custom_components/nhc2/entities/thermostat_thermostat_setpoint_temperature.py b/custom_components/nhc2/entities/thermostat_thermostat_setpoint_temperature.py index 16d5b43a..da90189e 100644 --- a/custom_components/nhc2/entities/thermostat_thermostat_setpoint_temperature.py +++ b/custom_components/nhc2/entities/thermostat_thermostat_setpoint_temperature.py @@ -25,6 +25,7 @@ def __init__(self, device_instance: CocoThermostatThermostat, hub, gateway): self._attr_native_value = self._device.setpoint_temperature self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_state_class = None + self._attr_suggested_display_precision = 1 @property def name(self) -> str: