From 4fecd5d8af0337fa8fb1bdd646f9fbf19d831e7b Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 23 Feb 2022 11:53:02 +0100 Subject: [PATCH] Fix type issues [fireservicerota] (#67094) Co-authored-by: Franck Nijhof --- .../components/fireservicerota/__init__.py | 10 ++++---- .../fireservicerota/binary_sensor.py | 24 ++++++++++++++----- .../components/fireservicerota/sensor.py | 5 ++-- .../components/fireservicerota/switch.py | 8 ++++--- mypy.ini | 12 ---------- script/hassfest/mypy_config.py | 4 ---- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/fireservicerota/__init__.py b/homeassistant/components/fireservicerota/__init__.py index 4cdb7ec0c42..ffd82307940 100644 --- a/homeassistant/components/fireservicerota/__init__.py +++ b/homeassistant/components/fireservicerota/__init__.py @@ -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) diff --git a/homeassistant/components/fireservicerota/binary_sensor.py b/homeassistant/components/fireservicerota/binary_sensor.py index c175e58cae8..9e4d5b123f5 100644 --- a/homeassistant/components/fireservicerota/binary_sensor.py +++ b/homeassistant/components/fireservicerota/binary_sensor.py @@ -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 diff --git a/homeassistant/components/fireservicerota/sensor.py b/homeassistant/components/fireservicerota/sensor.py index a17892a8591..66878b73145 100644 --- a/homeassistant/components/fireservicerota/sensor.py +++ b/homeassistant/components/fireservicerota/sensor.py @@ -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 diff --git a/homeassistant/components/fireservicerota/switch.py b/homeassistant/components/fireservicerota/switch.py index 7202420e571..e625ac5deb5 100644 --- a/homeassistant/components/fireservicerota/switch.py +++ b/homeassistant/components/fireservicerota/switch.py @@ -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 diff --git a/mypy.ini b/mypy.ini index 95c83dd1a5f..dbbbe824540 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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 diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index ae435c16ef0..8842b42fbd3 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -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",