mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Increase precision of Huisbaasje gas readings (#120138)
This commit is contained in:
parent
5e71eb4e0d
commit
ed2ad5ceaa
@ -54,7 +54,6 @@ class HuisbaasjeSensorEntityDescription(SensorEntityDescription):
|
||||
"""Class describing Airly sensor entities."""
|
||||
|
||||
sensor_type: str = SENSOR_TYPE_RATE
|
||||
precision: int = 0
|
||||
|
||||
|
||||
SENSORS_INFO = [
|
||||
@ -105,7 +104,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_ELECTRICITY_IN,
|
||||
sensor_type=SENSOR_TYPE_THIS_DAY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=3,
|
||||
suggested_display_precision=3,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_consumption_off_peak_today",
|
||||
@ -114,7 +113,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_ELECTRICITY_IN_LOW,
|
||||
sensor_type=SENSOR_TYPE_THIS_DAY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=3,
|
||||
suggested_display_precision=3,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_production_peak_today",
|
||||
@ -123,7 +122,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_ELECTRICITY_OUT,
|
||||
sensor_type=SENSOR_TYPE_THIS_DAY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=3,
|
||||
suggested_display_precision=3,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_production_off_peak_today",
|
||||
@ -132,7 +131,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_ELECTRICITY_OUT_LOW,
|
||||
sensor_type=SENSOR_TYPE_THIS_DAY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=3,
|
||||
suggested_display_precision=3,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_today",
|
||||
@ -141,7 +140,7 @@ SENSORS_INFO = [
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
key=SOURCE_TYPE_ELECTRICITY,
|
||||
sensor_type=SENSOR_TYPE_THIS_DAY,
|
||||
precision=1,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_week",
|
||||
@ -150,7 +149,7 @@ SENSORS_INFO = [
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
key=SOURCE_TYPE_ELECTRICITY,
|
||||
sensor_type=SENSOR_TYPE_THIS_WEEK,
|
||||
precision=1,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_month",
|
||||
@ -159,7 +158,7 @@ SENSORS_INFO = [
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
key=SOURCE_TYPE_ELECTRICITY,
|
||||
sensor_type=SENSOR_TYPE_THIS_MONTH,
|
||||
precision=1,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="energy_year",
|
||||
@ -168,7 +167,7 @@ SENSORS_INFO = [
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
key=SOURCE_TYPE_ELECTRICITY,
|
||||
sensor_type=SENSOR_TYPE_THIS_YEAR,
|
||||
precision=1,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="current_gas",
|
||||
@ -176,7 +175,7 @@ SENSORS_INFO = [
|
||||
sensor_type=SENSOR_TYPE_RATE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
key=SOURCE_TYPE_GAS,
|
||||
precision=1,
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="gas_today",
|
||||
@ -185,7 +184,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_GAS,
|
||||
sensor_type=SENSOR_TYPE_THIS_DAY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=1,
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="gas_week",
|
||||
@ -194,7 +193,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_GAS,
|
||||
sensor_type=SENSOR_TYPE_THIS_WEEK,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=1,
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="gas_month",
|
||||
@ -203,7 +202,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_GAS,
|
||||
sensor_type=SENSOR_TYPE_THIS_MONTH,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=1,
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
HuisbaasjeSensorEntityDescription(
|
||||
translation_key="gas_year",
|
||||
@ -212,7 +211,7 @@ SENSORS_INFO = [
|
||||
key=SOURCE_TYPE_GAS,
|
||||
sensor_type=SENSOR_TYPE_THIS_YEAR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
precision=1,
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
]
|
||||
|
||||
@ -253,7 +252,6 @@ class HuisbaasjeSensor(
|
||||
self.entity_description = description
|
||||
self._source_type = description.key
|
||||
self._sensor_type = description.sensor_type
|
||||
self._precision = description.precision
|
||||
self._attr_unique_id = (
|
||||
f"{DOMAIN}_{user_id}_{description.key}_{description.sensor_type}"
|
||||
)
|
||||
@ -266,7 +264,7 @@ class HuisbaasjeSensor(
|
||||
self.entity_description.sensor_type
|
||||
]
|
||||
) is not None:
|
||||
return round(data, self._precision)
|
||||
return data
|
||||
return None
|
||||
|
||||
@property
|
||||
|
@ -59,7 +59,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
|
||||
# Assert data is loaded
|
||||
current_power = hass.states.get("sensor.current_power")
|
||||
assert current_power.state == "1012.0"
|
||||
assert current_power.state == "1011.66666666667"
|
||||
assert (
|
||||
current_power.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
)
|
||||
@ -72,7 +72,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
current_power_in = hass.states.get("sensor.current_power_in_peak")
|
||||
assert current_power_in.state == "1012.0"
|
||||
assert current_power_in.state == "1011.66666666667"
|
||||
assert (
|
||||
current_power_in.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.POWER
|
||||
@ -134,7 +134,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
energy_consumption_peak_today = hass.states.get(
|
||||
"sensor.energy_consumption_peak_today"
|
||||
)
|
||||
assert energy_consumption_peak_today.state == "2.67"
|
||||
assert energy_consumption_peak_today.state == "2.669999453"
|
||||
assert (
|
||||
energy_consumption_peak_today.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -151,7 +151,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
energy_consumption_off_peak_today = hass.states.get(
|
||||
"sensor.energy_consumption_off_peak_today"
|
||||
)
|
||||
assert energy_consumption_off_peak_today.state == "0.627"
|
||||
assert energy_consumption_off_peak_today.state == "0.626666416"
|
||||
assert (
|
||||
energy_consumption_off_peak_today.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -168,7 +168,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
energy_production_peak_today = hass.states.get(
|
||||
"sensor.energy_production_peak_today"
|
||||
)
|
||||
assert energy_production_peak_today.state == "1.512"
|
||||
assert energy_production_peak_today.state == "1.51234"
|
||||
assert (
|
||||
energy_production_peak_today.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -185,7 +185,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
energy_production_off_peak_today = hass.states.get(
|
||||
"sensor.energy_production_off_peak_today"
|
||||
)
|
||||
assert energy_production_off_peak_today.state == "1.093"
|
||||
assert energy_production_off_peak_today.state == "1.09281"
|
||||
assert (
|
||||
energy_production_off_peak_today.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -200,7 +200,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
energy_today = hass.states.get("sensor.energy_today")
|
||||
assert energy_today.state == "3.3"
|
||||
assert energy_today.state == "3.296665869"
|
||||
assert (
|
||||
energy_today.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
)
|
||||
@ -211,7 +211,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
energy_this_week = hass.states.get("sensor.energy_this_week")
|
||||
assert energy_this_week.state == "17.5"
|
||||
assert energy_this_week.state == "17.509996085"
|
||||
assert (
|
||||
energy_this_week.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -225,7 +225,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
energy_this_month = hass.states.get("sensor.energy_this_month")
|
||||
assert energy_this_month.state == "103.3"
|
||||
assert energy_this_month.state == "103.28830788"
|
||||
assert (
|
||||
energy_this_month.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -239,7 +239,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
energy_this_year = hass.states.get("sensor.energy_this_year")
|
||||
assert energy_this_year.state == "673.0"
|
||||
assert energy_this_year.state == "672.97811773"
|
||||
assert (
|
||||
energy_this_year.attributes.get(ATTR_DEVICE_CLASS)
|
||||
== SensorDeviceClass.ENERGY
|
||||
@ -264,7 +264,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
gas_today = hass.states.get("sensor.gas_today")
|
||||
assert gas_today.state == "1.1"
|
||||
assert gas_today.state == "1.07"
|
||||
assert gas_today.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
gas_today.attributes.get(ATTR_STATE_CLASS)
|
||||
@ -276,7 +276,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
gas_this_week = hass.states.get("sensor.gas_this_week")
|
||||
assert gas_this_week.state == "5.6"
|
||||
assert gas_this_week.state == "5.634224386"
|
||||
assert gas_this_week.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
gas_this_week.attributes.get(ATTR_STATE_CLASS)
|
||||
@ -288,7 +288,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
gas_this_month = hass.states.get("sensor.gas_this_month")
|
||||
assert gas_this_month.state == "39.1"
|
||||
assert gas_this_month.state == "39.14"
|
||||
assert gas_this_month.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
gas_this_month.attributes.get(ATTR_STATE_CLASS)
|
||||
@ -300,7 +300,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
gas_this_year = hass.states.get("sensor.gas_this_year")
|
||||
assert gas_this_year.state == "116.7"
|
||||
assert gas_this_year.state == "116.73"
|
||||
assert gas_this_year.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
gas_this_year.attributes.get(ATTR_STATE_CLASS)
|
||||
@ -349,13 +349,13 @@ async def test_setup_entry_absent_measurement(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Assert data is loaded
|
||||
assert hass.states.get("sensor.current_power").state == "1012.0"
|
||||
assert hass.states.get("sensor.current_power").state == "1011.66666666667"
|
||||
assert hass.states.get("sensor.current_power_in_peak").state == "unknown"
|
||||
assert hass.states.get("sensor.current_power_in_off_peak").state == "unknown"
|
||||
assert hass.states.get("sensor.current_power_out_peak").state == "unknown"
|
||||
assert hass.states.get("sensor.current_power_out_off_peak").state == "unknown"
|
||||
assert hass.states.get("sensor.current_gas").state == "unknown"
|
||||
assert hass.states.get("sensor.energy_today").state == "3.3"
|
||||
assert hass.states.get("sensor.energy_today").state == "3.296665869"
|
||||
assert (
|
||||
hass.states.get("sensor.energy_consumption_peak_today").state == "unknown"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user