Fix Pure AQI value sensor in Sensibo (#124151)

* fix Pure AQI value sensor in Sensibo

* Fix tests

* Make enum
This commit is contained in:
G Johansson 2024-08-18 22:41:31 +02:00 committed by GitHub
parent 02b26ac4e6
commit 50f9c1e5a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 34 additions and 20 deletions

View File

@ -15,5 +15,5 @@
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["pysensibo"], "loggers": ["pysensibo"],
"quality_scale": "platinum", "quality_scale": "platinum",
"requirements": ["pysensibo==1.0.36"] "requirements": ["pysensibo==1.1.0"]
} }

View File

@ -7,7 +7,7 @@ from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
from pysensibo.model import MotionSensor, SensiboDevice from pysensibo.model import MotionSensor, PureAQI, SensiboDevice
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
SensorDeviceClass, SensorDeviceClass,
@ -97,11 +97,11 @@ MOTION_SENSOR_TYPES: tuple[SensiboMotionSensorEntityDescription, ...] = (
PURE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = ( PURE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
SensiboDeviceSensorEntityDescription( SensiboDeviceSensorEntityDescription(
key="pm25", key="pm25",
device_class=SensorDeviceClass.PM25, translation_key="pm25_pure",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, device_class=SensorDeviceClass.ENUM,
state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.pm25_pure.name.lower() if data.pm25_pure else None,
value_fn=lambda data: data.pm25,
extra_fn=None, extra_fn=None,
options=[aqi.name.lower() for aqi in PureAQI],
), ),
SensiboDeviceSensorEntityDescription( SensiboDeviceSensorEntityDescription(
key="pure_sensitivity", key="pure_sensitivity",

View File

@ -110,6 +110,14 @@
"s": "Sensitive" "s": "Sensitive"
} }
}, },
"pm25_pure": {
"name": "Pure AQI",
"state": {
"good": "Good",
"moderate": "Moderate",
"bad": "Bad"
}
},
"timer_time": { "timer_time": {
"name": "Timer end time" "name": "Timer end time"
}, },

View File

@ -2169,7 +2169,7 @@ pysaj==0.0.16
pyschlage==2024.8.0 pyschlage==2024.8.0
# homeassistant.components.sensibo # homeassistant.components.sensibo
pysensibo==1.0.36 pysensibo==1.1.0
# homeassistant.components.serial # homeassistant.components.serial
pyserial-asyncio-fast==0.13 pyserial-asyncio-fast==0.13

View File

@ -1732,7 +1732,7 @@ pysabnzbd==1.1.1
pyschlage==2024.8.0 pyschlage==2024.8.0
# homeassistant.components.sensibo # homeassistant.components.sensibo
pysensibo==1.0.36 pysensibo==1.1.0
# homeassistant.components.acer_projector # homeassistant.components.acer_projector
# homeassistant.components.crownstone # homeassistant.components.crownstone

View File

@ -91,7 +91,8 @@
'motion_sensors': dict({ 'motion_sensors': dict({
}), }),
'name': 'Kitchen', 'name': 'Kitchen',
'pm25': 1, 'pm25': None,
'pm25_pure': 1,
'pure_ac_integration': False, 'pure_ac_integration': False,
'pure_boost_enabled': False, 'pure_boost_enabled': False,
'pure_conf': dict({ 'pure_conf': dict({
@ -424,6 +425,7 @@
}), }),
'name': 'Hallway', 'name': 'Hallway',
'pm25': None, 'pm25': None,
'pm25_pure': None,
'pure_ac_integration': None, 'pure_ac_integration': None,
'pure_boost_enabled': None, 'pure_boost_enabled': None,
'pure_conf': dict({ 'pure_conf': dict({
@ -550,7 +552,8 @@
'motion_sensors': dict({ 'motion_sensors': dict({
}), }),
'name': 'Bedroom', 'name': 'Bedroom',
'pm25': 1, 'pm25': None,
'pm25_pure': 1,
'pure_ac_integration': False, 'pure_ac_integration': False,
'pure_boost_enabled': False, 'pure_boost_enabled': False,
'pure_conf': dict({ 'pure_conf': dict({

View File

@ -1,10 +1,13 @@
# serializer version: 1 # serializer version: 1
# name: test_sensor # name: test_sensor
ReadOnlyDict({ ReadOnlyDict({
'device_class': 'pm25', 'device_class': 'enum',
'friendly_name': 'Kitchen PM2.5', 'friendly_name': 'Kitchen Pure AQI',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'options': list([
'unit_of_measurement': 'µg/m³', 'good',
'moderate',
'bad',
]),
}) })
# --- # ---
# name: test_sensor.1 # name: test_sensor.1

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from unittest.mock import patch from unittest.mock import patch
from pysensibo.model import SensiboData from pysensibo.model import PureAQI, SensiboData
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
@ -27,17 +27,17 @@ async def test_sensor(
"""Test the Sensibo sensor.""" """Test the Sensibo sensor."""
state1 = hass.states.get("sensor.hallway_motion_sensor_battery_voltage") state1 = hass.states.get("sensor.hallway_motion_sensor_battery_voltage")
state2 = hass.states.get("sensor.kitchen_pm2_5") state2 = hass.states.get("sensor.kitchen_pure_aqi")
state3 = hass.states.get("sensor.kitchen_pure_sensitivity") state3 = hass.states.get("sensor.kitchen_pure_sensitivity")
state4 = hass.states.get("sensor.hallway_climate_react_low_temperature_threshold") state4 = hass.states.get("sensor.hallway_climate_react_low_temperature_threshold")
assert state1.state == "3000" assert state1.state == "3000"
assert state2.state == "1" assert state2.state == "good"
assert state3.state == "n" assert state3.state == "n"
assert state4.state == "0.0" assert state4.state == "0.0"
assert state2.attributes == snapshot assert state2.attributes == snapshot
assert state4.attributes == snapshot assert state4.attributes == snapshot
monkeypatch.setattr(get_data.parsed["AAZZAAZZ"], "pm25", 2) monkeypatch.setattr(get_data.parsed["AAZZAAZZ"], "pm25_pure", PureAQI(2))
with patch( with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data", "homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
@ -49,5 +49,5 @@ async def test_sensor(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state1 = hass.states.get("sensor.kitchen_pm2_5") state1 = hass.states.get("sensor.kitchen_pure_aqi")
assert state1.state == "2" assert state1.state == "moderate"