Enforce strict typing for OpenUV (#53409)
* Enforce strict typing for OpenUV * Linting * Fix tests
This commit is contained in:
parent
5c86cc502f
commit
54ace4cdd4
7 changed files with 92 additions and 66 deletions
|
@ -1,10 +1,14 @@
|
|||
"""Support for OpenUV sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TIME_MINUTES, UV_INDEX
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.dt import as_local, parse_datetime
|
||||
|
||||
from . import OpenUvEntity
|
||||
from . import OpenUV, OpenUvEntity
|
||||
from .const import (
|
||||
DATA_CLIENT,
|
||||
DATA_UV,
|
||||
|
@ -76,7 +80,9 @@ SENSORS = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up a OpenUV sensor based on a config entry."""
|
||||
openuv = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
|
||||
|
||||
|
@ -91,7 +97,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class OpenUvSensor(OpenUvEntity, SensorEntity):
|
||||
"""Define a binary sensor for OpenUV."""
|
||||
|
||||
def __init__(self, openuv, sensor_type, name, icon, unit):
|
||||
def __init__(
|
||||
self, openuv: OpenUV, sensor_type: str, name: str, icon: str, unit: str | None
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(openuv, sensor_type)
|
||||
|
||||
|
@ -100,7 +108,7 @@ class OpenUvSensor(OpenUvEntity, SensorEntity):
|
|||
self._attr_unit_of_measurement = unit
|
||||
|
||||
@callback
|
||||
def update_from_latest_data(self):
|
||||
def update_from_latest_data(self) -> None:
|
||||
"""Update the state."""
|
||||
data = self.openuv.data[DATA_UV].get("result")
|
||||
|
||||
|
@ -127,9 +135,11 @@ class OpenUvSensor(OpenUvEntity, SensorEntity):
|
|||
self._attr_state = UV_LEVEL_LOW
|
||||
elif self._sensor_type == TYPE_MAX_UV_INDEX:
|
||||
self._attr_state = data["uv_max"]
|
||||
self._attr_extra_state_attributes.update(
|
||||
{ATTR_MAX_UV_TIME: as_local(parse_datetime(data["uv_max_time"]))}
|
||||
)
|
||||
uv_max_time = parse_datetime(data["uv_max_time"])
|
||||
if uv_max_time:
|
||||
self._attr_extra_state_attributes.update(
|
||||
{ATTR_MAX_UV_TIME: as_local(uv_max_time)}
|
||||
)
|
||||
elif self._sensor_type in (
|
||||
TYPE_SAFE_EXPOSURE_TIME_1,
|
||||
TYPE_SAFE_EXPOSURE_TIME_2,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue