Add thermostat battery and signal sensors for Airzone integration (#142390)

* airzone: add thermostat battery/signal sensors

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>

* tests: airzone: use snapshot_platform for sensors

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>

* airzone: rename sensor strength

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>

---------

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
This commit is contained in:
Álvaro Fernández Rojas 2025-04-06 20:07:46 +02:00 committed by GitHub
parent bea389eed7
commit 7c488f1e54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1286 additions and 52 deletions

View File

@ -9,6 +9,8 @@ from aioairzone.const import (
AZD_HUMIDITY,
AZD_TEMP,
AZD_TEMP_UNIT,
AZD_THERMOSTAT_BATTERY,
AZD_THERMOSTAT_SIGNAL,
AZD_WEBSERVER,
AZD_WIFI_RSSI,
AZD_ZONES,
@ -73,6 +75,20 @@ ZONE_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
device_class=SensorDeviceClass.BATTERY,
key=AZD_THERMOSTAT_BATTERY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
key=AZD_THERMOSTAT_SIGNAL,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
translation_key="thermostat_signal",
),
)

View File

@ -76,6 +76,9 @@
"sensor": {
"rssi": {
"name": "RSSI"
},
"thermostat_signal": {
"name": "Signal strength"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,17 @@
"""The sensor tests for the Airzone platform."""
from collections.abc import Generator
import copy
from unittest.mock import patch
from aioairzone.const import API_DATA, API_SYSTEMS
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.airzone.coordinator import SCAN_INTERVAL
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.const import STATE_UNAVAILABLE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.util.dt import utcnow
from .util import (
@ -20,62 +23,27 @@ from .util import (
async_init_integration,
)
from tests.common import async_fire_time_changed
from tests.common import async_fire_time_changed, snapshot_platform
@pytest.fixture(autouse=True)
def override_platforms() -> Generator[None]:
"""Override PLATFORMS."""
with patch("homeassistant.components.airzone.PLATFORMS", [Platform.SENSOR]):
yield
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_airzone_create_sensors(hass: HomeAssistant) -> None:
async def test_airzone_create_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test creation of sensors."""
await async_init_integration(hass)
config_entry = await async_init_integration(hass)
# Hot Water
state = hass.states.get("sensor.airzone_dhw_temperature")
assert state.state == "43"
# WebServer
state = hass.states.get("sensor.airzone_webserver_rssi")
assert state.state == "-42"
# Zones
state = hass.states.get("sensor.despacho_temperature")
assert state.state == "21.20"
state = hass.states.get("sensor.despacho_humidity")
assert state.state == "36"
state = hass.states.get("sensor.dorm_1_temperature")
assert state.state == "20.8"
state = hass.states.get("sensor.dorm_1_humidity")
assert state.state == "35"
state = hass.states.get("sensor.dorm_2_temperature")
assert state.state == "20.5"
state = hass.states.get("sensor.dorm_2_humidity")
assert state.state == "40"
state = hass.states.get("sensor.dorm_ppal_temperature")
assert state.state == "21.1"
state = hass.states.get("sensor.dorm_ppal_humidity")
assert state.state == "39"
state = hass.states.get("sensor.salon_temperature")
assert state.state == "19.6"
state = hass.states.get("sensor.salon_humidity")
assert state.state == "34"
state = hass.states.get("sensor.airzone_2_1_temperature")
assert state.state == "22.3"
state = hass.states.get("sensor.airzone_2_1_humidity")
assert state.state == "62"
state = hass.states.get("sensor.dkn_plus_temperature")
assert state.state == "21.7"
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
state = hass.states.get("sensor.dkn_plus_humidity")
assert state is None

View File

@ -371,7 +371,7 @@ HVAC_WEBSERVER_MOCK = {
async def async_init_integration(
hass: HomeAssistant,
) -> None:
) -> MockConfigEntry:
"""Set up the Airzone integration in Home Assistant."""
config_entry = MockConfigEntry(
@ -407,3 +407,5 @@ async def async_init_integration(
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry