Fix types in ViCare integration (#101926)

* fix type

* fix return type

* fix type

* fix type

* Apply suggestions from code review

* Update climate.py

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update __init__.py

* Update climate.py

* Update __init__.py

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update binary_sensor.py

* Update button.py

* Update sensor.py

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Christopher Fenner 2023-10-13 23:13:39 +02:00 committed by GitHub
parent 6a6f6fd99d
commit ae7bb60677
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 15 deletions

View file

@ -1,11 +1,12 @@
"""The ViCare integration."""
from __future__ import annotations
from collections.abc import Callable
from collections.abc import Callable, Mapping
from contextlib import suppress
from dataclasses import dataclass
import logging
import os
from typing import Any
from PyViCare.PyViCare import PyViCare
from PyViCare.PyViCareDevice import Device
@ -59,7 +60,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True
def vicare_login(hass, entry_data):
def vicare_login(hass: HomeAssistant, entry_data: Mapping[str, Any]) -> PyViCare:
"""Login via PyVicare API."""
vicare_api = PyViCare()
vicare_api.setCacheDuration(DEFAULT_SCAN_INTERVAL)
@ -72,7 +73,7 @@ def vicare_login(hass, entry_data):
return vicare_api
def setup_vicare_api(hass, entry):
def setup_vicare_api(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Set up PyVicare API."""
vicare_api = vicare_login(hass, entry.data)

View file

@ -96,7 +96,9 @@ GLOBAL_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
)
def _build_entity(name, vicare_api, device_config, sensor):
def _build_entity(
name: str, vicare_api, device_config, sensor: ViCareBinarySensorEntityDescription
):
"""Create a ViCare binary sensor entity."""
try:
sensor.value_getter(vicare_api)
@ -117,8 +119,12 @@ def _build_entity(name, vicare_api, device_config, sensor):
async def _entities_from_descriptions(
hass, entities, sensor_descriptions, iterables, config_entry
):
hass: HomeAssistant,
entities: list[ViCareBinarySensor],
sensor_descriptions: tuple[ViCareBinarySensorEntityDescription, ...],
iterables,
config_entry: ConfigEntry,
) -> None:
"""Create entities from descriptions and list of burners/circuits."""
for description in sensor_descriptions:
for current in iterables:

View file

@ -46,7 +46,9 @@ BUTTON_DESCRIPTIONS: tuple[ViCareButtonEntityDescription, ...] = (
)
def _build_entity(name, vicare_api, device_config, description):
def _build_entity(
name: str, vicare_api, device_config, description: ViCareButtonEntityDescription
):
"""Create a ViCare button entity."""
_LOGGER.debug("Found device %s", name)
try:

View file

@ -67,7 +67,7 @@ VICARE_HOLD_MODE_OFF = "off"
VICARE_TEMP_HEATING_MIN = 3
VICARE_TEMP_HEATING_MAX = 37
VICARE_TO_HA_HVAC_HEATING = {
VICARE_TO_HA_HVAC_HEATING: dict[str, HVACMode] = {
VICARE_MODE_FORCEDREDUCED: HVACMode.OFF,
VICARE_MODE_OFF: HVACMode.OFF,
VICARE_MODE_DHW: HVACMode.OFF,
@ -146,15 +146,15 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
_attr_target_temperature_step = PRECISION_WHOLE
_attr_preset_modes = list(HA_TO_VICARE_PRESET_HEATING)
_current_action: bool | None = None
_current_mode: str | None = None
def __init__(self, name, api, circuit, device_config):
def __init__(self, name, api, circuit, device_config) -> None:
"""Initialize the climate device."""
super().__init__(device_config)
self._attr_name = name
self._api = api
self._circuit = circuit
self._attributes: dict[str, Any] = {}
self._current_mode = None
self._current_program = None
self._attr_unique_id = f"{device_config.getConfig().serial}-{circuit.id}"
@ -230,7 +230,9 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
@property
def hvac_mode(self) -> HVACMode | None:
"""Return current hvac mode."""
return VICARE_TO_HA_HVAC_HEATING.get(self._current_mode)
if self._current_mode is None:
return None
return VICARE_TO_HA_HVAC_HEATING.get(self._current_mode, None)
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set a new hvac mode on the ViCare API."""

View file

@ -573,7 +573,9 @@ COMPRESSOR_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
)
def _build_entity(name, vicare_api, device_config, sensor):
def _build_entity(
name: str, vicare_api, device_config, sensor: ViCareSensorEntityDescription
):
"""Create a ViCare sensor entity."""
_LOGGER.debug("Found device %s", name)
try:
@ -595,8 +597,12 @@ def _build_entity(name, vicare_api, device_config, sensor):
async def _entities_from_descriptions(
hass, entities, sensor_descriptions, iterables, config_entry
):
hass: HomeAssistant,
entities: list[ViCareSensor],
sensor_descriptions: tuple[ViCareSensorEntityDescription, ...],
iterables,
config_entry: ConfigEntry,
) -> None:
"""Create entities from descriptions and list of burners/circuits."""
for description in sensor_descriptions:
for current in iterables:

View file

@ -99,7 +99,7 @@ class ViCareWater(ViCareEntity, WaterHeaterEntity):
_attr_max_temp = VICARE_TEMP_WATER_MAX
_attr_operation_list = list(HA_TO_VICARE_HVAC_DHW)
def __init__(self, name, api, circuit, device_config):
def __init__(self, name, api, circuit, device_config) -> None:
"""Initialize the DHW water_heater device."""
super().__init__(device_config)
self._attr_name = name