mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Type check KNX integration weather, notify and scene (#48051)
This commit is contained in:
parent
987c2d1612
commit
943ce8afaf
@ -1,14 +1,25 @@
|
|||||||
"""Support for KNX/IP notification services."""
|
"""Support for KNX/IP notification services."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from xknx.devices import Notification as XknxNotification
|
from xknx.devices import Notification as XknxNotification
|
||||||
|
|
||||||
from homeassistant.components.notify import BaseNotificationService
|
from homeassistant.components.notify import BaseNotificationService
|
||||||
|
from homeassistant.helpers.typing import (
|
||||||
|
ConfigType,
|
||||||
|
DiscoveryInfoType,
|
||||||
|
HomeAssistantType,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
async def async_get_service(hass, config, discovery_info=None):
|
async def async_get_service(
|
||||||
|
hass: HomeAssistantType,
|
||||||
|
config: ConfigType,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> KNXNotificationService | None:
|
||||||
"""Get the KNX notification service."""
|
"""Get the KNX notification service."""
|
||||||
notification_devices = []
|
notification_devices = []
|
||||||
for device in hass.data[DOMAIN].xknx.devices:
|
for device in hass.data[DOMAIN].xknx.devices:
|
||||||
@ -22,31 +33,31 @@ async def async_get_service(hass, config, discovery_info=None):
|
|||||||
class KNXNotificationService(BaseNotificationService):
|
class KNXNotificationService(BaseNotificationService):
|
||||||
"""Implement demo notification service."""
|
"""Implement demo notification service."""
|
||||||
|
|
||||||
def __init__(self, devices: list[XknxNotification]):
|
def __init__(self, devices: list[XknxNotification]) -> None:
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
self.devices = devices
|
self.devices = devices
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def targets(self):
|
def targets(self) -> dict[str, str]:
|
||||||
"""Return a dictionary of registered targets."""
|
"""Return a dictionary of registered targets."""
|
||||||
ret = {}
|
ret = {}
|
||||||
for device in self.devices:
|
for device in self.devices:
|
||||||
ret[device.name] = device.name
|
ret[device.name] = device.name
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def async_send_message(self, message="", **kwargs):
|
async def async_send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||||
"""Send a notification to knx bus."""
|
"""Send a notification to knx bus."""
|
||||||
if "target" in kwargs:
|
if "target" in kwargs:
|
||||||
await self._async_send_to_device(message, kwargs["target"])
|
await self._async_send_to_device(message, kwargs["target"])
|
||||||
else:
|
else:
|
||||||
await self._async_send_to_all_devices(message)
|
await self._async_send_to_all_devices(message)
|
||||||
|
|
||||||
async def _async_send_to_all_devices(self, message):
|
async def _async_send_to_all_devices(self, message: str) -> None:
|
||||||
"""Send a notification to knx bus to all connected devices."""
|
"""Send a notification to knx bus to all connected devices."""
|
||||||
for device in self.devices:
|
for device in self.devices:
|
||||||
await device.set(message)
|
await device.set(message)
|
||||||
|
|
||||||
async def _async_send_to_device(self, message, names):
|
async def _async_send_to_device(self, message: str, names: str) -> None:
|
||||||
"""Send a notification to knx bus to device with given names."""
|
"""Send a notification to knx bus to device with given names."""
|
||||||
for device in self.devices:
|
for device in self.devices:
|
||||||
if device.name in names:
|
if device.name in names:
|
||||||
|
@ -1,15 +1,28 @@
|
|||||||
"""Support for KNX scenes."""
|
"""Support for KNX scenes."""
|
||||||
from typing import Any
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any, Callable, Iterable
|
||||||
|
|
||||||
from xknx.devices import Scene as XknxScene
|
from xknx.devices import Scene as XknxScene
|
||||||
|
|
||||||
from homeassistant.components.scene import Scene
|
from homeassistant.components.scene import Scene
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.helpers.typing import (
|
||||||
|
ConfigType,
|
||||||
|
DiscoveryInfoType,
|
||||||
|
HomeAssistantType,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .knx_entity import KnxEntity
|
from .knx_entity import KnxEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(
|
||||||
|
hass: HomeAssistantType,
|
||||||
|
config: ConfigType,
|
||||||
|
async_add_entities: Callable[[Iterable[Entity]], None],
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Set up the scenes for KNX platform."""
|
"""Set up the scenes for KNX platform."""
|
||||||
entities = []
|
entities = []
|
||||||
for device in hass.data[DOMAIN].xknx.devices:
|
for device in hass.data[DOMAIN].xknx.devices:
|
||||||
@ -21,8 +34,9 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
class KNXScene(KnxEntity, Scene):
|
class KNXScene(KnxEntity, Scene):
|
||||||
"""Representation of a KNX scene."""
|
"""Representation of a KNX scene."""
|
||||||
|
|
||||||
def __init__(self, device: XknxScene):
|
def __init__(self, device: XknxScene) -> None:
|
||||||
"""Init KNX scene."""
|
"""Init KNX scene."""
|
||||||
|
self._device: XknxScene
|
||||||
super().__init__(device)
|
super().__init__(device)
|
||||||
|
|
||||||
async def async_activate(self, **kwargs: Any) -> None:
|
async def async_activate(self, **kwargs: Any) -> None:
|
||||||
|
@ -1,16 +1,30 @@
|
|||||||
"""Support for KNX/IP weather station."""
|
"""Support for KNX/IP weather station."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Callable, Iterable
|
||||||
|
|
||||||
from xknx.devices import Weather as XknxWeather
|
from xknx.devices import Weather as XknxWeather
|
||||||
|
|
||||||
from homeassistant.components.weather import WeatherEntity
|
from homeassistant.components.weather import WeatherEntity
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.helpers.typing import (
|
||||||
|
ConfigType,
|
||||||
|
DiscoveryInfoType,
|
||||||
|
HomeAssistantType,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .knx_entity import KnxEntity
|
from .knx_entity import KnxEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(
|
||||||
"""Set up the scenes for KNX platform."""
|
hass: HomeAssistantType,
|
||||||
|
config: ConfigType,
|
||||||
|
async_add_entities: Callable[[Iterable[Entity]], None],
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""Set up weather entities for KNX platform."""
|
||||||
entities = []
|
entities = []
|
||||||
for device in hass.data[DOMAIN].xknx.devices:
|
for device in hass.data[DOMAIN].xknx.devices:
|
||||||
if isinstance(device, XknxWeather):
|
if isinstance(device, XknxWeather):
|
||||||
@ -21,22 +35,23 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
class KNXWeather(KnxEntity, WeatherEntity):
|
class KNXWeather(KnxEntity, WeatherEntity):
|
||||||
"""Representation of a KNX weather device."""
|
"""Representation of a KNX weather device."""
|
||||||
|
|
||||||
def __init__(self, device: XknxWeather):
|
def __init__(self, device: XknxWeather) -> None:
|
||||||
"""Initialize of a KNX sensor."""
|
"""Initialize of a KNX sensor."""
|
||||||
|
self._device: XknxWeather
|
||||||
super().__init__(device)
|
super().__init__(device)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self):
|
def temperature(self) -> float | None:
|
||||||
"""Return current temperature."""
|
"""Return current temperature."""
|
||||||
return self._device.temperature
|
return self._device.temperature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def temperature_unit(self) -> str:
|
||||||
"""Return temperature unit."""
|
"""Return temperature unit."""
|
||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pressure(self):
|
def pressure(self) -> float | None:
|
||||||
"""Return current air pressure."""
|
"""Return current air pressure."""
|
||||||
# KNX returns pA - HA requires hPa
|
# KNX returns pA - HA requires hPa
|
||||||
return (
|
return (
|
||||||
@ -46,22 +61,22 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self):
|
def condition(self) -> str:
|
||||||
"""Return current weather condition."""
|
"""Return current weather condition."""
|
||||||
return self._device.ha_current_state().value
|
return self._device.ha_current_state().value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def humidity(self):
|
def humidity(self) -> float | None:
|
||||||
"""Return current humidity."""
|
"""Return current humidity."""
|
||||||
return self._device.humidity
|
return self._device.humidity
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_bearing(self):
|
def wind_bearing(self) -> int | None:
|
||||||
"""Return current wind bearing in degrees."""
|
"""Return current wind bearing in degrees."""
|
||||||
return self._device.wind_bearing
|
return self._device.wind_bearing
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_speed(self):
|
def wind_speed(self) -> float | None:
|
||||||
"""Return current wind speed in km/h."""
|
"""Return current wind speed in km/h."""
|
||||||
# KNX only supports wind speed in m/s
|
# KNX only supports wind speed in m/s
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user