mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix type issues [fireservicerota] (#67094)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
0e54bd448a
commit
4fecd5d8af
@ -1,4 +1,6 @@
|
|||||||
"""The FireServiceRota integration."""
|
"""The FireServiceRota integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -195,25 +197,25 @@ class FireServiceRotaClient:
|
|||||||
|
|
||||||
return await self._hass.async_add_executor_job(func, *args)
|
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."""
|
"""Get the latest availability data."""
|
||||||
data = await self.update_call(
|
data = await self.update_call(
|
||||||
self.fsr.get_availability, str(self._hass.config.time_zone)
|
self.fsr.get_availability, str(self._hass.config.time_zone)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return None
|
||||||
|
|
||||||
self.on_duty = bool(data.get("available"))
|
self.on_duty = bool(data.get("available"))
|
||||||
|
|
||||||
_LOGGER.debug("Updated availability data: %s", data)
|
_LOGGER.debug("Updated availability data: %s", data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
async def async_response_update(self) -> object:
|
async def async_response_update(self) -> dict | None:
|
||||||
"""Get the latest incident response data."""
|
"""Get the latest incident response data."""
|
||||||
|
|
||||||
if not self.incident_id:
|
if not self.incident_id:
|
||||||
return
|
return None
|
||||||
|
|
||||||
_LOGGER.debug("Updating response data for incident id %s", self.incident_id)
|
_LOGGER.debug("Updating response data for incident id %s", self.incident_id)
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
"""Binary Sensor platform for FireServiceRota integration."""
|
"""Binary Sensor platform for FireServiceRota integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -8,6 +12,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from . import FireServiceRotaClient
|
||||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN as FIRESERVICEROTA_DOMAIN
|
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN as FIRESERVICEROTA_DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -16,7 +21,9 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up FireServiceRota binary sensor based on a config entry."""
|
"""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][
|
coordinator: DataUpdateCoordinator = hass.data[FIRESERVICEROTA_DOMAIN][
|
||||||
entry.entry_id
|
entry.entry_id
|
||||||
@ -28,13 +35,18 @@ async def async_setup_entry(
|
|||||||
class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||||
"""Representation of an FireServiceRota sensor."""
|
"""Representation of an FireServiceRota sensor."""
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, client, entry):
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: DataUpdateCoordinator,
|
||||||
|
client: FireServiceRotaClient,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._client = client
|
self._client = client
|
||||||
self._unique_id = f"{entry.unique_id}_Duty"
|
self._unique_id = f"{entry.unique_id}_Duty"
|
||||||
|
|
||||||
self._state = None
|
self._state: bool | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
@ -55,7 +67,7 @@ class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
|||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool | None:
|
||||||
"""Return the state of the binary sensor."""
|
"""Return the state of the binary sensor."""
|
||||||
|
|
||||||
self._state = self._client.on_duty
|
self._state = self._client.on_duty
|
||||||
@ -63,9 +75,9 @@ class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
|||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return available attributes for binary sensor."""
|
"""Return available attributes for binary sensor."""
|
||||||
attr = {}
|
attr: dict[str, Any] = {}
|
||||||
if not self.coordinator.data:
|
if not self.coordinator.data:
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Sensor platform for FireServiceRota integration."""
|
"""Sensor platform for FireServiceRota integration."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -65,9 +66,9 @@ class IncidentsSensor(RestoreEntity, SensorEntity):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> object:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return available attributes for sensor."""
|
"""Return available attributes for sensor."""
|
||||||
attr = {}
|
attr: dict[str, Any] = {}
|
||||||
|
|
||||||
if not (data := self._state_attributes):
|
if not (data := self._state_attributes):
|
||||||
return attr
|
return attr
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Switch platform for FireServiceRota integration."""
|
"""Switch platform for FireServiceRota integration."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -73,9 +74,9 @@ class ResponseSwitch(SwitchEntity):
|
|||||||
return self._client.on_duty
|
return self._client.on_duty
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> object:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return available attributes for switch."""
|
"""Return available attributes for switch."""
|
||||||
attr = {}
|
attr: dict[str, Any] = {}
|
||||||
if not self._state_attributes:
|
if not self._state_attributes:
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
@ -140,10 +141,11 @@ class ResponseSwitch(SwitchEntity):
|
|||||||
data = await self._client.async_response_update()
|
data = await self._client.async_response_update()
|
||||||
|
|
||||||
if not data or "status" not in data:
|
if not data or "status" not in data:
|
||||||
return
|
return False
|
||||||
|
|
||||||
self._state = data["status"] == "acknowledged"
|
self._state = data["status"] == "acknowledged"
|
||||||
self._state_attributes = data
|
self._state_attributes = data
|
||||||
self._state_icon = data["status"]
|
self._state_icon = data["status"]
|
||||||
|
|
||||||
_LOGGER.debug("Set state of entity 'Response Switch' to '%s'", self._state)
|
_LOGGER.debug("Set state of entity 'Response Switch' to '%s'", self._state)
|
||||||
|
return True
|
||||||
|
12
mypy.ini
12
mypy.ini
@ -2261,18 +2261,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.evohome.water_heater]
|
[mypy-homeassistant.components.evohome.water_heater]
|
||||||
ignore_errors = true
|
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]
|
[mypy-homeassistant.components.google_assistant.helpers]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -44,10 +44,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.evohome",
|
"homeassistant.components.evohome",
|
||||||
"homeassistant.components.evohome.climate",
|
"homeassistant.components.evohome.climate",
|
||||||
"homeassistant.components.evohome.water_heater",
|
"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.helpers",
|
||||||
"homeassistant.components.google_assistant.http",
|
"homeassistant.components.google_assistant.http",
|
||||||
"homeassistant.components.google_assistant.report_state",
|
"homeassistant.components.google_assistant.report_state",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user