Fix type issues [fireservicerota] (#67094)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
pull/66840/head
Marc Mueller 2022-02-23 11:53:02 +01:00 committed by GitHub
parent 0e54bd448a
commit 4fecd5d8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 31 deletions

View File

@ -1,4 +1,6 @@
"""The FireServiceRota integration."""
from __future__ import annotations
from datetime import timedelta
import logging
@ -195,25 +197,25 @@ class FireServiceRotaClient:
return await self._hass.async_add_executor_job(func, *args)
async def async_update(self) -> object:
async def async_update(self) -> dict | None:
"""Get the latest availability data."""
data = await self.update_call(
self.fsr.get_availability, str(self._hass.config.time_zone)
)
if not data:
return
return None
self.on_duty = bool(data.get("available"))
_LOGGER.debug("Updated availability data: %s", data)
return data
async def async_response_update(self) -> object:
async def async_response_update(self) -> dict | None:
"""Get the latest incident response data."""
if not self.incident_id:
return
return None
_LOGGER.debug("Updating response data for incident id %s", self.incident_id)

View File

@ -1,4 +1,8 @@
"""Binary Sensor platform for FireServiceRota integration."""
from __future__ import annotations
from typing import Any
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -8,6 +12,7 @@ from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
)
from . import FireServiceRotaClient
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN as FIRESERVICEROTA_DOMAIN
@ -16,7 +21,9 @@ async def async_setup_entry(
) -> None:
"""Set up FireServiceRota binary sensor based on a config entry."""
client = hass.data[FIRESERVICEROTA_DOMAIN][entry.entry_id][DATA_CLIENT]
client: FireServiceRotaClient = hass.data[FIRESERVICEROTA_DOMAIN][entry.entry_id][
DATA_CLIENT
]
coordinator: DataUpdateCoordinator = hass.data[FIRESERVICEROTA_DOMAIN][
entry.entry_id
@ -28,13 +35,18 @@ async def async_setup_entry(
class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
"""Representation of an FireServiceRota sensor."""
def __init__(self, coordinator: DataUpdateCoordinator, client, entry):
def __init__(
self,
coordinator: DataUpdateCoordinator,
client: FireServiceRotaClient,
entry: ConfigEntry,
) -> None:
"""Initialize."""
super().__init__(coordinator)
self._client = client
self._unique_id = f"{entry.unique_id}_Duty"
self._state = None
self._state: bool | None = None
@property
def name(self) -> str:
@ -55,7 +67,7 @@ class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
return self._unique_id
@property
def is_on(self) -> bool:
def is_on(self) -> bool | None:
"""Return the state of the binary sensor."""
self._state = self._client.on_duty
@ -63,9 +75,9 @@ class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
return self._state
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return available attributes for binary sensor."""
attr = {}
attr: dict[str, Any] = {}
if not self.coordinator.data:
return attr

View File

@ -1,5 +1,6 @@
"""Sensor platform for FireServiceRota integration."""
import logging
from typing import Any
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
@ -65,9 +66,9 @@ class IncidentsSensor(RestoreEntity, SensorEntity):
return False
@property
def extra_state_attributes(self) -> object:
def extra_state_attributes(self) -> dict[str, Any]:
"""Return available attributes for sensor."""
attr = {}
attr: dict[str, Any] = {}
if not (data := self._state_attributes):
return attr

View File

@ -1,5 +1,6 @@
"""Switch platform for FireServiceRota integration."""
import logging
from typing import Any
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
@ -73,9 +74,9 @@ class ResponseSwitch(SwitchEntity):
return self._client.on_duty
@property
def extra_state_attributes(self) -> object:
def extra_state_attributes(self) -> dict[str, Any]:
"""Return available attributes for switch."""
attr = {}
attr: dict[str, Any] = {}
if not self._state_attributes:
return attr
@ -140,10 +141,11 @@ class ResponseSwitch(SwitchEntity):
data = await self._client.async_response_update()
if not data or "status" not in data:
return
return False
self._state = data["status"] == "acknowledged"
self._state_attributes = data
self._state_icon = data["status"]
_LOGGER.debug("Set state of entity 'Response Switch' to '%s'", self._state)
return True

View File

@ -2261,18 +2261,6 @@ ignore_errors = true
[mypy-homeassistant.components.evohome.water_heater]
ignore_errors = true
[mypy-homeassistant.components.fireservicerota]
ignore_errors = true
[mypy-homeassistant.components.fireservicerota.binary_sensor]
ignore_errors = true
[mypy-homeassistant.components.fireservicerota.sensor]
ignore_errors = true
[mypy-homeassistant.components.fireservicerota.switch]
ignore_errors = true
[mypy-homeassistant.components.google_assistant.helpers]
ignore_errors = true

View File

@ -44,10 +44,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.evohome",
"homeassistant.components.evohome.climate",
"homeassistant.components.evohome.water_heater",
"homeassistant.components.fireservicerota",
"homeassistant.components.fireservicerota.binary_sensor",
"homeassistant.components.fireservicerota.sensor",
"homeassistant.components.fireservicerota.switch",
"homeassistant.components.google_assistant.helpers",
"homeassistant.components.google_assistant.http",
"homeassistant.components.google_assistant.report_state",