Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ homeassistant.components.aftership.*
homeassistant.components.air_quality.*
homeassistant.components.airly.*
homeassistant.components.airvisual.*
homeassistant.components.airzone.*
homeassistant.components.aladdin_connect.*
homeassistant.components.alarm_control_panel.*
homeassistant.components.amazon_polly.*
Expand Down
28 changes: 12 additions & 16 deletions homeassistant/components/airzone/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for the Airzone sensors."""
from __future__ import annotations

from collections.abc import Mapping
from dataclasses import dataclass
from typing import Any, Final

Expand All @@ -22,7 +21,7 @@
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

Expand Down Expand Up @@ -120,20 +119,15 @@ class AirzoneBinarySensor(AirzoneEntity, BinarySensorEntity):

entity_description: AirzoneBinarySensorEntityDescription

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return state attributes."""
if not self.entity_description.attributes:
return None
return {
key: self.get_airzone_value(val)
for key, val in self.entity_description.attributes.items()
}

@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
return self.get_airzone_value(self.entity_description.key)
@callback
def _async_update_attrs(self) -> None:
"""Update binary sensor attributes."""
self._attr_is_on = self.get_airzone_value(self.entity_description.key)
if self.entity_description.attributes:
self._attr_extra_state_attributes = {
key: self.get_airzone_value(val)
for key, val in self.entity_description.attributes.items()
}


class AirzoneSystemBinarySensor(AirzoneSystemEntity, AirzoneBinarySensor):
Expand All @@ -152,6 +146,7 @@ def __init__(
self._attr_name = f"System {system_id} {description.name}"
self._attr_unique_id = f"{self._attr_unique_id}_{system_id}_{description.key}"
self.entity_description = description
self._async_update_attrs()


class AirzoneZoneBinarySensor(AirzoneZoneEntity, AirzoneBinarySensor):
Expand All @@ -173,3 +168,4 @@ def __init__(
f"{self._attr_unique_id}_{system_zone_id}_{description.key}"
)
self.entity_description = description
self._async_update_attrs()
2 changes: 1 addition & 1 deletion homeassistant/components/airzone/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
params[API_ON] = 1
await self._async_update_hvac_params(params)

async def async_set_temperature(self, **kwargs) -> None:
async def async_set_temperature(self, **kwargs: dict[str, Any]) -> None:
"""Set new target temperature."""
params = {
API_SET_POINT: kwargs.get(ATTR_TEMPERATURE),
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/airzone/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from datetime import timedelta
import logging
from typing import Any, cast

from aioairzone.exceptions import AirzoneError
from aioairzone.localapi import AirzoneLocalApi
Expand All @@ -18,7 +19,7 @@
_LOGGER = logging.getLogger(__name__)


class AirzoneUpdateCoordinator(DataUpdateCoordinator):
class AirzoneUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
"""Class to manage fetching data from the Airzone device."""

def __init__(self, hass: HomeAssistant, airzone: AirzoneLocalApi) -> None:
Expand All @@ -30,13 +31,14 @@ def __init__(self, hass: HomeAssistant, airzone: AirzoneLocalApi) -> None:
_LOGGER,
name=DOMAIN,
update_interval=SCAN_INTERVAL,
update_method=self._async_update,
)

async def _async_update_data(self):
async def _async_update(self) -> dict[str, Any]:
"""Update data via library."""
async with async_timeout.timeout(AIOAIRZONE_DEVICE_TIMEOUT_SEC):
try:
await self.airzone.update()
except AirzoneError as error:
raise UpdateFailed(error) from error
return self.airzone.data()
return cast(dict[str, Any], self.airzone.data())
6 changes: 3 additions & 3 deletions homeassistant/components/airzone/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class AirzoneEntity(CoordinatorEntity[AirzoneUpdateCoordinator]):
"""Define an Airzone entity."""

def get_airzone_value(self, key) -> Any:
def get_airzone_value(self, key: str) -> Any:
"""Return Airzone entity value by key."""
raise NotImplementedError()

Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(
entry.entry_id if entry.unique_id is None else entry.unique_id
)

def get_airzone_value(self, key) -> Any:
def get_airzone_value(self, key: str) -> Any:
"""Return system value by key."""
value = None
if system := self.coordinator.data[AZD_SYSTEMS].get(self.system_id):
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(
entry.entry_id if entry.unique_id is None else entry.unique_id
)

def get_airzone_value(self, key) -> Any:
def get_airzone_value(self, key: str) -> Any:
"""Return zone value by key."""
value = None
if zone := self.coordinator.data[AZD_ZONES].get(self.system_zone_id):
Expand Down
12 changes: 7 additions & 5 deletions homeassistant/components/airzone/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, TEMP_UNIT_LIB_TO_HASS
Expand Down Expand Up @@ -64,10 +64,10 @@ async def async_setup_entry(
class AirzoneSensor(AirzoneEntity, SensorEntity):
"""Define an Airzone sensor."""

@property
def native_value(self):
"""Return the state."""
return self.get_airzone_value(self.entity_description.key)
@callback
def _async_update_attrs(self) -> None:
"""Update sensor attributes."""
self._attr_native_value = self.get_airzone_value(self.entity_description.key)


class AirzoneZoneSensor(AirzoneZoneEntity, AirzoneSensor):
Expand All @@ -94,3 +94,5 @@ def __init__(
self._attr_native_unit_of_measurement = TEMP_UNIT_LIB_TO_HASS.get(
self.get_airzone_value(AZD_TEMP_UNIT)
)

self._async_update_attrs()
11 changes: 11 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-homeassistant.components.airzone.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-homeassistant.components.aladdin_connect.*]
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down