From b6572d1cabf92d9b5e2f2480dcd942a4615712b4 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 23 Feb 2022 09:55:26 +0100 Subject: [PATCH] Fix type issues [geniushub] (#67095) --- .../components/geniushub/__init__.py | 20 +++++++------------ .../components/geniushub/binary_sensor.py | 4 ++-- homeassistant/components/geniushub/sensor.py | 19 ++++++++++-------- .../components/geniushub/water_heater.py | 2 +- mypy.ini | 15 -------------- script/hassfest/mypy_config.py | 5 ----- 6 files changed, 21 insertions(+), 44 deletions(-) diff --git a/homeassistant/components/geniushub/__init__.py b/homeassistant/components/geniushub/__init__.py index 38a0ff15af3..83e358acc34 100644 --- a/homeassistant/components/geniushub/__init__.py +++ b/homeassistant/components/geniushub/__init__.py @@ -1,7 +1,7 @@ """Support for a Genius Hub system.""" from __future__ import annotations -from datetime import timedelta +from datetime import datetime, timedelta import logging from typing import Any @@ -223,7 +223,7 @@ class GeniusEntity(Entity): def __init__(self) -> None: """Initialize the entity.""" - self._unique_id = self._name = None + self._unique_id: str | None = None async def async_added_to_hass(self) -> None: """Set up a listener when this entity is added to HA.""" @@ -238,11 +238,6 @@ class GeniusEntity(Entity): """Return a unique ID.""" return self._unique_id - @property - def name(self) -> str: - """Return the name of the geniushub entity.""" - return self._name - @property def should_poll(self) -> bool: """Return False as geniushub entities should not be polled.""" @@ -258,7 +253,8 @@ class GeniusDevice(GeniusEntity): self._device = device self._unique_id = f"{broker.hub_uid}_device_{device.id}" - self._last_comms = self._state_attr = None + self._last_comms: datetime | None = None + self._state_attr = None @property def extra_state_attributes(self) -> dict[str, Any]: @@ -337,11 +333,9 @@ class GeniusZone(GeniusEntity): class GeniusHeatingZone(GeniusZone): """Base for Genius Heating Zones.""" - def __init__(self, broker, zone) -> None: - """Initialize the Zone.""" - super().__init__(broker, zone) - - self._max_temp = self._min_temp = self._supported_features = None + _max_temp: float + _min_temp: float + _supported_features: int @property def current_temperature(self) -> float | None: diff --git a/homeassistant/components/geniushub/binary_sensor.py b/homeassistant/components/geniushub/binary_sensor.py index 1e54df52820..f00019361e5 100644 --- a/homeassistant/components/geniushub/binary_sensor.py +++ b/homeassistant/components/geniushub/binary_sensor.py @@ -42,9 +42,9 @@ class GeniusBinarySensor(GeniusDevice, BinarySensorEntity): self._state_attr = state_attr if device.type[:21] == "Dual Channel Receiver": - self._name = f"{device.type[:21]} {device.id}" + self._attr_name = f"{device.type[:21]} {device.id}" else: - self._name = f"{device.type} {device.id}" + self._attr_name = f"{device.type} {device.id}" @property def is_on(self) -> bool: diff --git a/homeassistant/components/geniushub/sensor.py b/homeassistant/components/geniushub/sensor.py index fad66c49312..20acb533a2c 100644 --- a/homeassistant/components/geniushub/sensor.py +++ b/homeassistant/components/geniushub/sensor.py @@ -34,14 +34,14 @@ async def async_setup_platform( broker = hass.data[DOMAIN]["broker"] - sensors = [ + entities: list[GeniusBattery | GeniusIssue] = [ GeniusBattery(broker, d, GH_STATE_ATTR) for d in broker.client.device_objs if GH_STATE_ATTR in d.data["state"] ] - issues = [GeniusIssue(broker, i) for i in list(GH_LEVEL_MAPPING)] + entities.extend([GeniusIssue(broker, i) for i in list(GH_LEVEL_MAPPING)]) - async_add_entities(sensors + issues, update_before_add=True) + async_add_entities(entities, update_before_add=True) class GeniusBattery(GeniusDevice, SensorEntity): @@ -53,7 +53,7 @@ class GeniusBattery(GeniusDevice, SensorEntity): self._state_attr = state_attr - self._name = f"{device.type} {device.id}" + self._attr_name = f"{device.type} {device.id}" @property def icon(self) -> str: @@ -62,7 +62,10 @@ class GeniusBattery(GeniusDevice, SensorEntity): interval = timedelta( seconds=self._device.data["_state"].get("wakeupInterval", 30 * 60) ) - if self._last_comms < dt_util.utcnow() - interval * 3: + if ( + not self._last_comms + or self._last_comms < dt_util.utcnow() - interval * 3 + ): return "mdi:battery-unknown" battery_level = self._device.data["state"][self._state_attr] @@ -104,12 +107,12 @@ class GeniusIssue(GeniusEntity, SensorEntity): self._hub = broker.client self._unique_id = f"{broker.hub_uid}_{GH_LEVEL_MAPPING[level]}" - self._name = f"GeniusHub {GH_LEVEL_MAPPING[level]}" + self._attr_name = f"GeniusHub {GH_LEVEL_MAPPING[level]}" self._level = level - self._issues = [] + self._issues: list = [] @property - def native_value(self) -> str: + def native_value(self) -> int: """Return the number of issues.""" return len(self._issues) diff --git a/homeassistant/components/geniushub/water_heater.py b/homeassistant/components/geniushub/water_heater.py index f1ff8444d28..a64aa1345e1 100644 --- a/homeassistant/components/geniushub/water_heater.py +++ b/homeassistant/components/geniushub/water_heater.py @@ -73,7 +73,7 @@ class GeniusWaterHeater(GeniusHeatingZone, WaterHeaterEntity): @property def current_operation(self) -> str: """Return the current operation mode.""" - return GH_STATE_TO_HA[self._zone.data["mode"]] + return GH_STATE_TO_HA[self._zone.data["mode"]] # type: ignore[return-value] async def async_set_operation_mode(self, operation_mode) -> None: """Set a new operation mode for this boiler.""" diff --git a/mypy.ini b/mypy.ini index 887a65394b7..95c83dd1a5f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2273,21 +2273,6 @@ ignore_errors = true [mypy-homeassistant.components.fireservicerota.switch] ignore_errors = true -[mypy-homeassistant.components.geniushub] -ignore_errors = true - -[mypy-homeassistant.components.geniushub.binary_sensor] -ignore_errors = true - -[mypy-homeassistant.components.geniushub.climate] -ignore_errors = true - -[mypy-homeassistant.components.geniushub.sensor] -ignore_errors = true - -[mypy-homeassistant.components.geniushub.water_heater] -ignore_errors = true - [mypy-homeassistant.components.google_assistant.helpers] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index a78e07e057b..ae435c16ef0 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -48,11 +48,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.fireservicerota.binary_sensor", "homeassistant.components.fireservicerota.sensor", "homeassistant.components.fireservicerota.switch", - "homeassistant.components.geniushub", - "homeassistant.components.geniushub.binary_sensor", - "homeassistant.components.geniushub.climate", - "homeassistant.components.geniushub.sensor", - "homeassistant.components.geniushub.water_heater", "homeassistant.components.google_assistant.helpers", "homeassistant.components.google_assistant.http", "homeassistant.components.google_assistant.report_state",