diff --git a/.strict-typing b/.strict-typing index 8f7ca3311c2..fa2addb86bd 100644 --- a/.strict-typing +++ b/.strict-typing @@ -101,6 +101,7 @@ homeassistant.components.number.* homeassistant.components.onewire.* homeassistant.components.open_meteo.* homeassistant.components.openuv.* +homeassistant.components.overkiz.* homeassistant.components.persistent_notification.* homeassistant.components.pi_hole.* homeassistant.components.proximity.* diff --git a/homeassistant/components/overkiz/binary_sensor.py b/homeassistant/components/overkiz/binary_sensor.py index 8f4fc8be948..507c36f88a9 100644 --- a/homeassistant/components/overkiz/binary_sensor.py +++ b/homeassistant/components/overkiz/binary_sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Callable from dataclasses import dataclass +from typing import cast from pyoverkiz.enums import OverkizCommandParam, OverkizState @@ -40,28 +41,28 @@ BINARY_SENSOR_DESCRIPTIONS: list[OverkizBinarySensorDescription] = [ key=OverkizState.CORE_RAIN, name="Rain", icon="mdi:weather-rainy", - value_fn=lambda state: state == OverkizCommandParam.DETECTED, + value_fn=lambda state: state == cast(str, OverkizCommandParam.DETECTED), ), # SmokeSensor/SmokeSensor OverkizBinarySensorDescription( key=OverkizState.CORE_SMOKE, name="Smoke", device_class=BinarySensorDeviceClass.SMOKE, - value_fn=lambda state: state == OverkizCommandParam.DETECTED, + value_fn=lambda state: state == cast(str, OverkizCommandParam.DETECTED), ), # WaterSensor/WaterDetectionSensor OverkizBinarySensorDescription( key=OverkizState.CORE_WATER_DETECTION, name="Water", icon="mdi:water", - value_fn=lambda state: state == OverkizCommandParam.DETECTED, + value_fn=lambda state: state == cast(str, OverkizCommandParam.DETECTED), ), # AirSensor/AirFlowSensor OverkizBinarySensorDescription( key=OverkizState.CORE_GAS_DETECTION, name="Gas", device_class=BinarySensorDeviceClass.GAS, - value_fn=lambda state: state == OverkizCommandParam.DETECTED, + value_fn=lambda state: state == cast(str, OverkizCommandParam.DETECTED), ), # OccupancySensor/OccupancySensor # OccupancySensor/MotionSensor @@ -69,35 +70,35 @@ BINARY_SENSOR_DESCRIPTIONS: list[OverkizBinarySensorDescription] = [ key=OverkizState.CORE_OCCUPANCY, name="Occupancy", device_class=BinarySensorDeviceClass.OCCUPANCY, - value_fn=lambda state: state == OverkizCommandParam.PERSON_INSIDE, + value_fn=lambda state: state == cast(str, OverkizCommandParam.PERSON_INSIDE), ), # ContactSensor/WindowWithTiltSensor OverkizBinarySensorDescription( key=OverkizState.CORE_VIBRATION, name="Vibration", device_class=BinarySensorDeviceClass.VIBRATION, - value_fn=lambda state: state == OverkizCommandParam.DETECTED, + value_fn=lambda state: state == cast(str, OverkizCommandParam.DETECTED), ), # ContactSensor/ContactSensor OverkizBinarySensorDescription( key=OverkizState.CORE_CONTACT, name="Contact", device_class=BinarySensorDeviceClass.DOOR, - value_fn=lambda state: state == OverkizCommandParam.OPEN, + value_fn=lambda state: state == cast(str, OverkizCommandParam.OPEN), ), # Siren/SirenStatus OverkizBinarySensorDescription( key=OverkizState.CORE_ASSEMBLY, name="Assembly", device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda state: state == OverkizCommandParam.OPEN, + value_fn=lambda state: state == cast(str, OverkizCommandParam.OPEN), ), # Unknown OverkizBinarySensorDescription( key=OverkizState.IO_VIBRATION_DETECTED, name="Vibration", device_class=BinarySensorDeviceClass.VIBRATION, - value_fn=lambda state: state == OverkizCommandParam.DETECTED, + value_fn=lambda state: state == cast(str, OverkizCommandParam.DETECTED), ), ] @@ -106,7 +107,7 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback, -): +) -> None: """Set up the Overkiz binary sensors from a config entry.""" data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] entities: list[OverkizBinarySensor] = [] diff --git a/homeassistant/components/overkiz/coordinator.py b/homeassistant/components/overkiz/coordinator.py index ce0344c49dd..96ee918b750 100644 --- a/homeassistant/components/overkiz/coordinator.py +++ b/homeassistant/components/overkiz/coordinator.py @@ -5,7 +5,7 @@ from collections.abc import Callable from datetime import timedelta import json import logging -from typing import Any +from typing import Any, cast from aiohttp import ServerDisconnectedError from pyoverkiz.client import OverkizClient @@ -168,10 +168,14 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator): data_type = DataType(state.type) if data_type == DataType.NONE: - return state.value + return cast(None, state.value) cast_to_python = DATA_TYPE_TO_PYTHON[data_type] - return cast_to_python(state.value) + value = cast_to_python(state.value) + + assert isinstance(value, (str, float, int, bool)) + + return value def places_to_area(self, place: Place) -> dict[str, str]: """Convert places with sub_places to a flat dictionary.""" diff --git a/homeassistant/components/overkiz/executor.py b/homeassistant/components/overkiz/executor.py index 55bda409e2d..71ed9b0b7d7 100644 --- a/homeassistant/components/overkiz/executor.py +++ b/homeassistant/components/overkiz/executor.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging -from typing import Any +from typing import Any, cast from urllib.parse import urlparse from pyoverkiz.models import Command, Device @@ -41,7 +41,7 @@ class OverkizExecutor: """Select first existing active state in a list of states.""" for state in states: if current_state := self.device.states[state]: - return current_state.value + return cast(str, current_state.value) return None @@ -53,7 +53,7 @@ class OverkizExecutor: """Select first existing active state in a list of states.""" for attribute in attributes: if current_attribute := self.device.attributes[attribute]: - return current_attribute.value + return cast(str, current_attribute.value) return None diff --git a/homeassistant/components/overkiz/light.py b/homeassistant/components/overkiz/light.py index 8c93741dbb7..4e8aa820710 100644 --- a/homeassistant/components/overkiz/light.py +++ b/homeassistant/components/overkiz/light.py @@ -1,7 +1,7 @@ """Support for Overkiz lights.""" from __future__ import annotations -from typing import Any +from typing import Any, cast from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState @@ -59,9 +59,8 @@ class OverkizLight(OverkizEntity, LightEntity): @property def is_on(self) -> bool: """Return true if light is on.""" - return ( - self.executor.select_state(OverkizState.CORE_ON_OFF) - == OverkizCommandParam.ON + return self.executor.select_state(OverkizState.CORE_ON_OFF) == cast( + str, OverkizCommandParam.ON ) @property diff --git a/homeassistant/components/overkiz/lock.py b/homeassistant/components/overkiz/lock.py index 8a333652b75..b4e92586d57 100644 --- a/homeassistant/components/overkiz/lock.py +++ b/homeassistant/components/overkiz/lock.py @@ -1,7 +1,7 @@ """Support for Overkiz locks.""" from __future__ import annotations -from typing import Any +from typing import Any, cast from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState @@ -44,7 +44,6 @@ class OverkizLock(OverkizEntity, LockEntity): @property def is_locked(self) -> bool | None: """Return a boolean for the state of the lock.""" - return ( - self.executor.select_state(OverkizState.CORE_LOCKED_UNLOCKED) - == OverkizCommandParam.LOCKED + return self.executor.select_state(OverkizState.CORE_LOCKED_UNLOCKED) == cast( + str, OverkizCommandParam.LOCKED ) diff --git a/homeassistant/components/overkiz/number.py b/homeassistant/components/overkiz/number.py index bf5a0ce1a24..e849e419e67 100644 --- a/homeassistant/components/overkiz/number.py +++ b/homeassistant/components/overkiz/number.py @@ -2,6 +2,7 @@ from __future__ import annotations from dataclasses import dataclass +from typing import cast from pyoverkiz.enums import OverkizCommand, OverkizState @@ -92,7 +93,7 @@ class OverkizNumber(OverkizDescriptiveEntity, NumberEntity): def value(self) -> float | None: """Return the entity value to represent the entity state.""" if state := self.device.states.get(self.entity_description.key): - return state.value + return cast(float, state.value) return None diff --git a/homeassistant/components/overkiz/sensor.py b/homeassistant/components/overkiz/sensor.py index a62bf574819..3283151ee7d 100644 --- a/homeassistant/components/overkiz/sensor.py +++ b/homeassistant/components/overkiz/sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Callable from dataclasses import dataclass +from typing import cast from pyoverkiz.enums import OverkizAttribute, OverkizState, UIWidget @@ -401,7 +402,7 @@ class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity): if self.entity_description.native_value: return self.entity_description.native_value(state.value) - return state.value + return cast(str, state.value) class OverkizHomeKitSetupCodeSensor(OverkizEntity, SensorEntity): @@ -418,9 +419,11 @@ class OverkizHomeKitSetupCodeSensor(OverkizEntity, SensorEntity): self._attr_name = "HomeKit Setup Code" @property - def native_value(self) -> str: + def native_value(self) -> str | None: """Return the value of the sensor.""" - return self.device.attributes.get(OverkizAttribute.HOMEKIT_SETUP_CODE).value + if state := self.device.attributes.get(OverkizAttribute.HOMEKIT_SETUP_CODE): + return cast(str, state.value) + return None @property def device_info(self) -> DeviceInfo: diff --git a/mypy.ini b/mypy.ini index db85c57ae96..3eb62acb3ce 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1122,6 +1122,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.overkiz.*] +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.persistent_notification.*] check_untyped_defs = true disallow_incomplete_defs = true