mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Use absolute humidity device class in HomematicIP Cloud (#148905)
This commit is contained in:
parent
45dbf3ef1a
commit
993b0bbdd7
@ -46,6 +46,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
CONCENTRATION_GRAMS_PER_CUBIC_METER,
|
||||||
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
|
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
|
||||||
DEGREE,
|
DEGREE,
|
||||||
LIGHT_LUX,
|
LIGHT_LUX,
|
||||||
@ -542,7 +543,9 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity):
|
|||||||
class HomematicipAbsoluteHumiditySensor(HomematicipGenericEntity, SensorEntity):
|
class HomematicipAbsoluteHumiditySensor(HomematicipGenericEntity, SensorEntity):
|
||||||
"""Representation of the HomematicIP absolute humidity sensor."""
|
"""Representation of the HomematicIP absolute humidity sensor."""
|
||||||
|
|
||||||
_attr_native_unit_of_measurement = CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER
|
_attr_device_class = SensorDeviceClass.ABSOLUTE_HUMIDITY
|
||||||
|
_attr_native_unit_of_measurement = CONCENTRATION_GRAMS_PER_CUBIC_METER
|
||||||
|
_attr_suggested_unit_of_measurement = CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER
|
||||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
@ -550,7 +553,7 @@ class HomematicipAbsoluteHumiditySensor(HomematicipGenericEntity, SensorEntity):
|
|||||||
super().__init__(hap, device, post="Absolute Humidity")
|
super().__init__(hap, device, post="Absolute Humidity")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> int | None:
|
def native_value(self) -> float | None:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
if self.functional_channel is None:
|
if self.functional_channel is None:
|
||||||
return None
|
return None
|
||||||
@ -564,8 +567,7 @@ class HomematicipAbsoluteHumiditySensor(HomematicipGenericEntity, SensorEntity):
|
|||||||
):
|
):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Convert from g/m³ to mg/m³
|
return round(value, 3)
|
||||||
return int(float(value) * 1000)
|
|
||||||
|
|
||||||
|
|
||||||
class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity):
|
class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity):
|
||||||
|
@ -776,7 +776,7 @@ async def test_hmip_absolute_humidity_sensor(
|
|||||||
hass, mock_hap, entity_id, entity_name, device_model
|
hass, mock_hap, entity_id, entity_name, device_model
|
||||||
)
|
)
|
||||||
|
|
||||||
assert ha_state.state == "6098"
|
assert ha_state.state == "6099.0"
|
||||||
|
|
||||||
|
|
||||||
async def test_hmip_absolute_humidity_sensor_invalid_value(
|
async def test_hmip_absolute_humidity_sensor_invalid_value(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user