Fix type issues [geniushub] (#67095)

pull/67094/head
Marc Mueller 2022-02-23 09:55:26 +01:00 committed by GitHub
parent 459e6c273b
commit b6572d1cab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 44 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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)

View File

@ -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."""

View File

@ -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

View File

@ -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",