Skip to content

Commit

Permalink
Merge pull request #86 from tijsverkoyen/use-native-value
Browse files Browse the repository at this point in the history
Bugfix: Make changing Unit of Measurement through interface work.
  • Loading branch information
tijsverkoyen authored Sep 26, 2023
2 parents bcee268 + 0af8ff4 commit 86cab28
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
if self._device.electrical_power > 0:
return self._device.electrical_power

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
if self._device.electrical_power < 0:
return -self._device.electrical_power

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power_consumption

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power_from_grid

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power_production

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power_self_consumption

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericEnergyhome, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power_to_grid

def on_change(self):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/nhc2/entities/generic_fan_co2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericFan, hub, gateway):
self._attr_native_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION
self._attr_state_class = None
self._attr_suggested_display_precision = 0
self._attr_native_precision = 0

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> int:
def native_value(self) -> int:
return self._device.co2

def on_change(self):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/nhc2/entities/generic_fan_humidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoGenericFan, hub, gateway):
self._attr_native_unit_of_measurement = PERCENTAGE
self._attr_state_class = None
self._attr_suggested_display_precision = 0
self._attr_native_precision = 0

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> int:
def native_value(self) -> int:
return self._device.humidity

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoHvacthermostatHvac, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_state_class = None
self._attr_suggested_display_precision = 1
self._attr_native_precision = 1

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.overrule_setpoint

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def device_info(self):
}

@property
def state(self) -> int:
def native_value(self) -> int:
return self._device.overrule_time

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoHvacthermostatHvac, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_state_class = None
self._attr_suggested_display_precision = 1
self._attr_native_precision = 1

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.setpoint_temperature

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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
self._attr_suggested_display_precision = 3
self._attr_native_precision = 3

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.electrical_power

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoThermostatHvac, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_state_class = None
self._attr_suggested_display_precision = 1
self._attr_native_precision = 1

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.overrule_setpoint

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def device_info(self):
}

@property
def state(self) -> int:
def native_value(self) -> int:
return self._device.overrule_time

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoThermostatHvac, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_state_class = None
self._attr_suggested_display_precision = 1
self._attr_native_precision = 1

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.setpoint_temperature

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoThermostatThermostat, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_state_class = None
self._attr_suggested_display_precision = 1
self._attr_native_precision = 1

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.overrule_setpoint

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def device_info(self):
}

@property
def state(self) -> int:
def native_value(self) -> int:
return self._device.overrule_time

def on_change(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, device_instance: CocoThermostatThermostat, hub, gateway):
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_state_class = None
self._attr_suggested_display_precision = 1
self._attr_native_precision = 1

@property
def name(self) -> str:
Expand All @@ -45,7 +46,7 @@ def device_info(self):
}

@property
def state(self) -> float:
def native_value(self) -> float:
return self._device.setpoint_temperature

def on_change(self):
Expand Down

0 comments on commit 86cab28

Please sign in to comment.