Skip to content

Commit

Permalink
Fix Pure AQI value sensor in Sensibo (#124151)
Browse files Browse the repository at this point in the history
* fix Pure AQI value sensor in Sensibo

* Fix tests

* Make enum
  • Loading branch information
gjohansson-ST authored Aug 18, 2024
1 parent 02b26ac commit 50f9c1e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/sensibo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"iot_class": "cloud_polling",
"loggers": ["pysensibo"],
"quality_scale": "platinum",
"requirements": ["pysensibo==1.0.36"]
"requirements": ["pysensibo==1.1.0"]
}
10 changes: 5 additions & 5 deletions homeassistant/components/sensibo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import datetime
from typing import TYPE_CHECKING, Any

from pysensibo.model import MotionSensor, SensiboDevice
from pysensibo.model import MotionSensor, PureAQI, SensiboDevice

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -97,11 +97,11 @@ class SensiboDeviceSensorEntityDescription(SensorEntityDescription):
PURE_SENSOR_TYPES: tuple[SensiboDeviceSensorEntityDescription, ...] = (
SensiboDeviceSensorEntityDescription(
key="pm25",
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda data: data.pm25,
translation_key="pm25_pure",
device_class=SensorDeviceClass.ENUM,
value_fn=lambda data: data.pm25_pure.name.lower() if data.pm25_pure else None,
extra_fn=None,
options=[aqi.name.lower() for aqi in PureAQI],
),
SensiboDeviceSensorEntityDescription(
key="pure_sensitivity",
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/sensibo/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
"s": "Sensitive"
}
},
"pm25_pure": {
"name": "Pure AQI",
"state": {
"good": "Good",
"moderate": "Moderate",
"bad": "Bad"
}
},
"timer_time": {
"name": "Timer end time"
},
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@ pysaj==0.0.16
pyschlage==2024.8.0

# homeassistant.components.sensibo
pysensibo==1.0.36
pysensibo==1.1.0

# homeassistant.components.serial
pyserial-asyncio-fast==0.13
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ pysabnzbd==1.1.1
pyschlage==2024.8.0

# homeassistant.components.sensibo
pysensibo==1.0.36
pysensibo==1.1.0

# homeassistant.components.acer_projector
# homeassistant.components.crownstone
Expand Down
7 changes: 5 additions & 2 deletions tests/components/sensibo/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
'motion_sensors': dict({
}),
'name': 'Kitchen',
'pm25': 1,
'pm25': None,
'pm25_pure': 1,
'pure_ac_integration': False,
'pure_boost_enabled': False,
'pure_conf': dict({
Expand Down Expand Up @@ -424,6 +425,7 @@
}),
'name': 'Hallway',
'pm25': None,
'pm25_pure': None,
'pure_ac_integration': None,
'pure_boost_enabled': None,
'pure_conf': dict({
Expand Down Expand Up @@ -550,7 +552,8 @@
'motion_sensors': dict({
}),
'name': 'Bedroom',
'pm25': 1,
'pm25': None,
'pm25_pure': 1,
'pure_ac_integration': False,
'pure_boost_enabled': False,
'pure_conf': dict({
Expand Down
11 changes: 7 additions & 4 deletions tests/components/sensibo/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# serializer version: 1
# name: test_sensor
ReadOnlyDict({
'device_class': 'pm25',
'friendly_name': 'Kitchen PM2.5',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
'device_class': 'enum',
'friendly_name': 'Kitchen Pure AQI',
'options': list([
'good',
'moderate',
'bad',
]),
})
# ---
# name: test_sensor.1
Expand Down
12 changes: 6 additions & 6 deletions tests/components/sensibo/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import timedelta
from unittest.mock import patch

from pysensibo.model import SensiboData
from pysensibo.model import PureAQI, SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion

Expand All @@ -27,17 +27,17 @@ async def test_sensor(
"""Test the Sensibo sensor."""

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")
state4 = hass.states.get("sensor.hallway_climate_react_low_temperature_threshold")
assert state1.state == "3000"
assert state2.state == "1"
assert state2.state == "good"
assert state3.state == "n"
assert state4.state == "0.0"
assert state2.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(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
Expand All @@ -49,5 +49,5 @@ async def test_sensor(
)
await hass.async_block_till_done()

state1 = hass.states.get("sensor.kitchen_pm2_5")
assert state1.state == "2"
state1 = hass.states.get("sensor.kitchen_pure_aqi")
assert state1.state == "moderate"

0 comments on commit 50f9c1e

Please sign in to comment.