mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Add strict typing to glances (#99537)
This commit is contained in:
parent
1dc724274e
commit
8d3828ae54
@ -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.*
|
||||
|
@ -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 {}
|
||||
|
@ -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])
|
||||
|
10
mypy.ini
10
mypy.ini
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user