Add strict typing to glances (#99537)

This commit is contained in:
Rami Mosleh 2023-09-04 10:07:15 +03:00 committed by GitHub
parent 1dc724274e
commit 8d3828ae54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View File

@ -136,6 +136,7 @@ homeassistant.components.fully_kiosk.*
homeassistant.components.geo_location.*
homeassistant.components.geocaching.*
homeassistant.components.gios.*
homeassistant.components.glances.*
homeassistant.components.goalzero.*
homeassistant.components.google.*
homeassistant.components.google_sheets.*

View File

@ -35,6 +35,7 @@ class GlancesDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
async def _async_update_data(self) -> dict[str, Any]:
"""Get the latest data from the Glances REST API."""
try:
return await self.api.get_ha_sensor_data()
data = await self.api.get_ha_sensor_data()
except exceptions.GlancesApiError as err:
raise UpdateFailed from err
return data or {}

View File

@ -2,6 +2,7 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import cast
from homeassistant.components.sensor import (
SensorDeviceClass,
@ -346,5 +347,7 @@ class GlancesSensor(CoordinatorEntity[GlancesDataUpdateCoordinator], SensorEntit
value = self.coordinator.data[self.entity_description.type]
if isinstance(value.get(self._sensor_name_prefix), dict):
return value[self._sensor_name_prefix][self.entity_description.key]
return value[self.entity_description.key]
return cast(
StateType, value[self._sensor_name_prefix][self.entity_description.key]
)
return cast(StateType, value[self.entity_description.key])

View File

@ -1122,6 +1122,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.glances.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.goalzero.*]
check_untyped_defs = true
disallow_incomplete_defs = true