forked from home-assistant/core
Compare commits
115 Commits
2022.8.0b2
...
2022.8.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2fae855e7 | ||
|
|
fdde4d540d | ||
|
|
5606b4026f | ||
|
|
84b8029c6a | ||
|
|
294cc3ac6e | ||
|
|
99c20223e5 | ||
|
|
451ab47caa | ||
|
|
738423056e | ||
|
|
a3ea881a01 | ||
|
|
2dcc886b2f | ||
|
|
6e688b2b7f | ||
|
|
0fd38ef9f8 | ||
|
|
56c80cd31a | ||
|
|
303d8b05d1 | ||
|
|
972c05eac8 | ||
|
|
e5088d7e84 | ||
|
|
6c1597ff98 | ||
|
|
edac82487d | ||
|
|
5213148fa8 | ||
|
|
8e3f5ec470 | ||
|
|
af90159e7c | ||
|
|
f01b0a1a62 | ||
|
|
ee2acabcbe | ||
|
|
79b371229d | ||
|
|
0f6b059e3e | ||
|
|
bfb2867e8d | ||
|
|
c9581f6a2e | ||
|
|
e96903fddf | ||
|
|
5026bff426 | ||
|
|
4b63aa7f15 | ||
|
|
1c2dd78e4c | ||
|
|
9cf11cf6ed | ||
|
|
8971a2073e | ||
|
|
bfa64d2e01 | ||
|
|
9c21d56539 | ||
|
|
8bfc352524 | ||
|
|
0e7bf35e4a | ||
|
|
1dd701a89a | ||
|
|
d266b1ced6 | ||
|
|
6727dab330 | ||
|
|
42509056bd | ||
|
|
a370e4f4b0 | ||
|
|
a17e99f714 | ||
|
|
db227a888d | ||
|
|
1808dd3d84 | ||
|
|
31fed328ce | ||
|
|
1a030f118a | ||
|
|
a4049e93d8 | ||
|
|
854ca853dc | ||
|
|
2710e4b5ec | ||
|
|
450af52bac | ||
|
|
60da54558e | ||
|
|
11319defae | ||
|
|
6340da72a5 | ||
|
|
5c9d557b10 | ||
|
|
d2955a48b0 | ||
|
|
d2b98fa285 | ||
|
|
8ef3ca2daf | ||
|
|
80a053a4cd | ||
|
|
81ee24738b | ||
|
|
29f6d7818a | ||
|
|
bc1e371cae | ||
|
|
42a1f6ca20 | ||
|
|
d85129c527 | ||
|
|
ad14b5f3d7 | ||
|
|
51a6899a60 | ||
|
|
d2dc83c4c7 | ||
|
|
d7a418a219 | ||
|
|
a78da6a000 | ||
|
|
690f051a87 | ||
|
|
c22cb13bd0 | ||
|
|
213812f087 | ||
|
|
19b0961084 | ||
|
|
e073f6b439 | ||
|
|
c4906414ea | ||
|
|
cc9a130f58 | ||
|
|
c90a223cb6 | ||
|
|
2eddbf2381 | ||
|
|
654e26052b | ||
|
|
676664022d | ||
|
|
ed57951571 | ||
|
|
b9ee81dfc3 | ||
|
|
da00f5ba1e | ||
|
|
30cd087f6f | ||
|
|
66afd1e696 | ||
|
|
23488f392b | ||
|
|
7140a9d025 | ||
|
|
4f671bccbc | ||
|
|
6b588d41ff | ||
|
|
b962a6e767 | ||
|
|
a332eb154c | ||
|
|
75747ce319 | ||
|
|
c6038380d6 | ||
|
|
990975e908 | ||
|
|
2a58bf06c1 | ||
|
|
5ab549653b | ||
|
|
ffd2813150 | ||
|
|
ebf91fe46b | ||
|
|
e330147751 | ||
|
|
26a3621bb3 | ||
|
|
58265664d1 | ||
|
|
d205fb5064 | ||
|
|
38ae2f4e9e | ||
|
|
d84bc20a58 | ||
|
|
a3276e00b9 | ||
|
|
bdb627539e | ||
|
|
240890e496 | ||
|
|
e2a9ab1831 | ||
|
|
8f8bccd982 | ||
|
|
26c475d3dc | ||
|
|
0f0b51bee7 | ||
|
|
241ffe07b9 | ||
|
|
c3c5442467 | ||
|
|
d7827d9902 | ||
|
|
176d44190e |
@@ -388,6 +388,7 @@ omit =
|
||||
homeassistant/components/flume/__init__.py
|
||||
homeassistant/components/flume/sensor.py
|
||||
homeassistant/components/flunearyou/__init__.py
|
||||
homeassistant/components/flunearyou/repairs.py
|
||||
homeassistant/components/flunearyou/sensor.py
|
||||
homeassistant/components/folder/sensor.py
|
||||
homeassistant/components/folder_watcher/*
|
||||
|
||||
@@ -128,6 +128,7 @@ homeassistant.components.homekit.util
|
||||
homeassistant.components.homekit_controller
|
||||
homeassistant.components.homekit_controller.alarm_control_panel
|
||||
homeassistant.components.homekit_controller.button
|
||||
homeassistant.components.homekit_controller.config_flow
|
||||
homeassistant.components.homekit_controller.const
|
||||
homeassistant.components.homekit_controller.lock
|
||||
homeassistant.components.homekit_controller.select
|
||||
|
||||
@@ -1044,8 +1044,8 @@ build.json @home-assistant/supervisor
|
||||
/tests/components/switch/ @home-assistant/core
|
||||
/homeassistant/components/switch_as_x/ @home-assistant/core
|
||||
/tests/components/switch_as_x/ @home-assistant/core
|
||||
/homeassistant/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas
|
||||
/tests/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas
|
||||
/homeassistant/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas @Eloston
|
||||
/tests/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas @Eloston
|
||||
/homeassistant/components/switcher_kis/ @tomerfi @thecode
|
||||
/tests/components/switcher_kis/ @tomerfi @thecode
|
||||
/homeassistant/components/switchmate/ @danielhiversen @qiz-li
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "aladdin_connect",
|
||||
"name": "Aladdin Connect",
|
||||
"documentation": "https://www.home-assistant.io/integrations/aladdin_connect",
|
||||
"requirements": ["AIOAladdinConnect==0.1.31"],
|
||||
"requirements": ["AIOAladdinConnect==0.1.41"],
|
||||
"codeowners": ["@mkmer"],
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["aladdin_connect"],
|
||||
|
||||
@@ -68,16 +68,19 @@ API_TEMP_UNITS = {TEMP_FAHRENHEIT: "FAHRENHEIT", TEMP_CELSIUS: "CELSIUS"}
|
||||
# back to HA state.
|
||||
API_THERMOSTAT_MODES = OrderedDict(
|
||||
[
|
||||
(climate.HVAC_MODE_HEAT, "HEAT"),
|
||||
(climate.HVAC_MODE_COOL, "COOL"),
|
||||
(climate.HVAC_MODE_HEAT_COOL, "AUTO"),
|
||||
(climate.HVAC_MODE_AUTO, "AUTO"),
|
||||
(climate.HVAC_MODE_OFF, "OFF"),
|
||||
(climate.HVAC_MODE_FAN_ONLY, "OFF"),
|
||||
(climate.HVAC_MODE_DRY, "CUSTOM"),
|
||||
(climate.HVACMode.HEAT, "HEAT"),
|
||||
(climate.HVACMode.COOL, "COOL"),
|
||||
(climate.HVACMode.HEAT_COOL, "AUTO"),
|
||||
(climate.HVACMode.AUTO, "AUTO"),
|
||||
(climate.HVACMode.OFF, "OFF"),
|
||||
(climate.HVACMode.FAN_ONLY, "CUSTOM"),
|
||||
(climate.HVACMode.DRY, "CUSTOM"),
|
||||
]
|
||||
)
|
||||
API_THERMOSTAT_MODES_CUSTOM = {climate.HVAC_MODE_DRY: "DEHUMIDIFY"}
|
||||
API_THERMOSTAT_MODES_CUSTOM = {
|
||||
climate.HVACMode.DRY: "DEHUMIDIFY",
|
||||
climate.HVACMode.FAN_ONLY: "FAN",
|
||||
}
|
||||
API_THERMOSTAT_PRESETS = {climate.PRESET_ECO: "ECO"}
|
||||
|
||||
# AlexaModeController does not like a single mode for the fan preset, we add PRESET_MODE_NA if a fan has only one preset_mode
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Apple TV",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/apple_tv",
|
||||
"requirements": ["pyatv==0.10.2"],
|
||||
"requirements": ["pyatv==0.10.3"],
|
||||
"dependencies": ["zeroconf"],
|
||||
"zeroconf": [
|
||||
"_mediaremotetv._tcp.local.",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "azure_service_bus",
|
||||
"name": "Azure Service Bus",
|
||||
"documentation": "https://www.home-assistant.io/integrations/azure_service_bus",
|
||||
"requirements": ["azure-servicebus==0.50.3"],
|
||||
"requirements": ["azure-servicebus==7.8.0"],
|
||||
"codeowners": ["@hfurubotten"],
|
||||
"iot_class": "cloud_push",
|
||||
"loggers": ["azure"]
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
from azure.servicebus.aio import Message, ServiceBusClient
|
||||
from azure.servicebus.common.errors import (
|
||||
MessageSendFailed,
|
||||
from azure.servicebus import ServiceBusMessage
|
||||
from azure.servicebus.aio import ServiceBusClient
|
||||
from azure.servicebus.exceptions import (
|
||||
MessagingEntityNotFoundError,
|
||||
ServiceBusConnectionError,
|
||||
ServiceBusResourceNotFound,
|
||||
ServiceBusError,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -60,10 +61,10 @@ def get_service(hass, config, discovery_info=None):
|
||||
|
||||
try:
|
||||
if queue_name:
|
||||
client = servicebus.get_queue(queue_name)
|
||||
client = servicebus.get_queue_sender(queue_name)
|
||||
else:
|
||||
client = servicebus.get_topic(topic_name)
|
||||
except (ServiceBusConnectionError, ServiceBusResourceNotFound) as err:
|
||||
client = servicebus.get_topic_sender(topic_name)
|
||||
except (ServiceBusConnectionError, MessagingEntityNotFoundError) as err:
|
||||
_LOGGER.error(
|
||||
"Connection error while creating client for queue/topic '%s'. %s",
|
||||
queue_name or topic_name,
|
||||
@@ -93,11 +94,12 @@ class ServiceBusNotificationService(BaseNotificationService):
|
||||
if data := kwargs.get(ATTR_DATA):
|
||||
dto.update(data)
|
||||
|
||||
queue_message = Message(json.dumps(dto))
|
||||
queue_message.properties.content_type = CONTENT_TYPE_JSON
|
||||
queue_message = ServiceBusMessage(
|
||||
json.dumps(dto), content_type=CONTENT_TYPE_JSON
|
||||
)
|
||||
try:
|
||||
await self._client.send(queue_message)
|
||||
except MessageSendFailed as err:
|
||||
await self._client.send_messages(queue_message)
|
||||
except ServiceBusError as err:
|
||||
_LOGGER.error(
|
||||
"Could not send service bus notification to %s. %s",
|
||||
self._client.name,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Big Ass Fans",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/baf",
|
||||
"requirements": ["aiobafi6==0.7.0"],
|
||||
"requirements": ["aiobafi6==0.7.2"],
|
||||
"codeowners": ["@bdraco", "@jfroy"],
|
||||
"iot_class": "local_push",
|
||||
"zeroconf": [
|
||||
|
||||
@@ -8,12 +8,12 @@ from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
import logging
|
||||
from typing import Final, Union
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
import async_timeout
|
||||
from bleak import BleakError
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from dbus_next import InvalidMessageError
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
@@ -27,8 +27,8 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import discovery_flow
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import async_get_bluetooth
|
||||
from homeassistant.util.package import is_docker_env
|
||||
|
||||
from . import models
|
||||
from .const import CONF_ADAPTER, DEFAULT_ADAPTERS, DOMAIN
|
||||
@@ -42,14 +42,25 @@ from .models import HaBleakScanner, HaBleakScannerWrapper
|
||||
from .usage import install_multiple_bleak_catcher, uninstall_multiple_bleak_catcher
|
||||
from .util import async_get_bluetooth_adapters
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
UNAVAILABLE_TRACK_SECONDS: Final = 60 * 5
|
||||
START_TIMEOUT = 15
|
||||
START_TIMEOUT = 9
|
||||
|
||||
SOURCE_LOCAL: Final = "local"
|
||||
|
||||
SCANNER_WATCHDOG_TIMEOUT: Final = 60 * 5
|
||||
SCANNER_WATCHDOG_INTERVAL: Final = timedelta(seconds=SCANNER_WATCHDOG_TIMEOUT)
|
||||
MONOTONIC_TIME = time.monotonic
|
||||
|
||||
|
||||
@dataclass
|
||||
class BluetoothServiceInfoBleak(BluetoothServiceInfo):
|
||||
@@ -96,12 +107,8 @@ SCANNING_MODE_TO_BLEAK = {
|
||||
|
||||
|
||||
BluetoothChange = Enum("BluetoothChange", "ADVERTISEMENT")
|
||||
BluetoothCallback = Callable[
|
||||
[Union[BluetoothServiceInfoBleak, BluetoothServiceInfo], BluetoothChange], None
|
||||
]
|
||||
ProcessAdvertisementCallback = Callable[
|
||||
[Union[BluetoothServiceInfoBleak, BluetoothServiceInfo]], bool
|
||||
]
|
||||
BluetoothCallback = Callable[[BluetoothServiceInfoBleak, BluetoothChange], None]
|
||||
ProcessAdvertisementCallback = Callable[[BluetoothServiceInfoBleak], bool]
|
||||
|
||||
|
||||
@hass_callback
|
||||
@@ -157,9 +164,15 @@ def async_register_callback(
|
||||
hass: HomeAssistant,
|
||||
callback: BluetoothCallback,
|
||||
match_dict: BluetoothCallbackMatcher | None,
|
||||
mode: BluetoothScanningMode,
|
||||
) -> Callable[[], None]:
|
||||
"""Register to receive a callback on bluetooth change.
|
||||
|
||||
mode is currently not used as we only support active scanning.
|
||||
Passive scanning will be available in the future. The flag
|
||||
is required to be present to avoid a future breaking change
|
||||
when we support passive scanning.
|
||||
|
||||
Returns a callback that can be used to cancel the registration.
|
||||
"""
|
||||
manager: BluetoothManager = hass.data[DOMAIN]
|
||||
@@ -170,19 +183,20 @@ async def async_process_advertisements(
|
||||
hass: HomeAssistant,
|
||||
callback: ProcessAdvertisementCallback,
|
||||
match_dict: BluetoothCallbackMatcher,
|
||||
mode: BluetoothScanningMode,
|
||||
timeout: int,
|
||||
) -> BluetoothServiceInfo:
|
||||
) -> BluetoothServiceInfoBleak:
|
||||
"""Process advertisements until callback returns true or timeout expires."""
|
||||
done: Future[BluetoothServiceInfo] = Future()
|
||||
done: Future[BluetoothServiceInfoBleak] = Future()
|
||||
|
||||
@hass_callback
|
||||
def _async_discovered_device(
|
||||
service_info: BluetoothServiceInfo, change: BluetoothChange
|
||||
service_info: BluetoothServiceInfoBleak, change: BluetoothChange
|
||||
) -> None:
|
||||
if callback(service_info):
|
||||
if not done.done() and callback(service_info):
|
||||
done.set_result(service_info)
|
||||
|
||||
unload = async_register_callback(hass, _async_discovered_device, match_dict)
|
||||
unload = async_register_callback(hass, _async_discovered_device, match_dict, mode)
|
||||
|
||||
try:
|
||||
async with async_timeout.timeout(timeout):
|
||||
@@ -243,9 +257,10 @@ async def async_setup_entry(
|
||||
) -> bool:
|
||||
"""Set up the bluetooth integration from a config entry."""
|
||||
manager: BluetoothManager = hass.data[DOMAIN]
|
||||
await manager.async_start(
|
||||
BluetoothScanningMode.ACTIVE, entry.options.get(CONF_ADAPTER)
|
||||
)
|
||||
async with manager.start_stop_lock:
|
||||
await manager.async_start(
|
||||
BluetoothScanningMode.ACTIVE, entry.options.get(CONF_ADAPTER)
|
||||
)
|
||||
entry.async_on_unload(entry.add_update_listener(_async_update_listener))
|
||||
return True
|
||||
|
||||
@@ -254,8 +269,6 @@ async def _async_update_listener(
|
||||
hass: HomeAssistant, entry: config_entries.ConfigEntry
|
||||
) -> None:
|
||||
"""Handle options update."""
|
||||
manager: BluetoothManager = hass.data[DOMAIN]
|
||||
manager.async_start_reload()
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
@@ -264,7 +277,9 @@ async def async_unload_entry(
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
manager: BluetoothManager = hass.data[DOMAIN]
|
||||
await manager.async_stop()
|
||||
async with manager.start_stop_lock:
|
||||
manager.async_start_reload()
|
||||
await manager.async_stop()
|
||||
return True
|
||||
|
||||
|
||||
@@ -280,13 +295,19 @@ class BluetoothManager:
|
||||
self.hass = hass
|
||||
self._integration_matcher = integration_matcher
|
||||
self.scanner: HaBleakScanner | None = None
|
||||
self.start_stop_lock = asyncio.Lock()
|
||||
self._cancel_device_detected: CALLBACK_TYPE | None = None
|
||||
self._cancel_unavailable_tracking: CALLBACK_TYPE | None = None
|
||||
self._cancel_stop: CALLBACK_TYPE | None = None
|
||||
self._cancel_watchdog: CALLBACK_TYPE | None = None
|
||||
self._unavailable_callbacks: dict[str, list[Callable[[str], None]]] = {}
|
||||
self._callbacks: list[
|
||||
tuple[BluetoothCallback, BluetoothCallbackMatcher | None]
|
||||
] = []
|
||||
self._last_detection = 0.0
|
||||
self._reloading = False
|
||||
self._adapter: str | None = None
|
||||
self._scanning_mode = BluetoothScanningMode.ACTIVE
|
||||
|
||||
@hass_callback
|
||||
def async_setup(self) -> None:
|
||||
@@ -308,6 +329,8 @@ class BluetoothManager:
|
||||
) -> None:
|
||||
"""Set up BT Discovery."""
|
||||
assert self.scanner is not None
|
||||
self._adapter = adapter
|
||||
self._scanning_mode = scanning_mode
|
||||
if self._reloading:
|
||||
# On reload, we need to reset the scanner instance
|
||||
# since the devices in its history may not be reachable
|
||||
@@ -333,17 +356,71 @@ class BluetoothManager:
|
||||
)
|
||||
try:
|
||||
async with async_timeout.timeout(START_TIMEOUT):
|
||||
await self.scanner.start()
|
||||
await self.scanner.start() # type: ignore[no-untyped-call]
|
||||
except InvalidMessageError as ex:
|
||||
self._cancel_device_detected()
|
||||
_LOGGER.debug("Invalid DBus message received: %s", ex, exc_info=True)
|
||||
raise ConfigEntryNotReady(
|
||||
f"Invalid DBus message received: {ex}; try restarting `dbus`"
|
||||
) from ex
|
||||
except BrokenPipeError as ex:
|
||||
self._cancel_device_detected()
|
||||
_LOGGER.debug("DBus connection broken: %s", ex, exc_info=True)
|
||||
if is_docker_env():
|
||||
raise ConfigEntryNotReady(
|
||||
f"DBus connection broken: {ex}; try restarting `bluetooth`, `dbus`, and finally the docker container"
|
||||
) from ex
|
||||
raise ConfigEntryNotReady(
|
||||
f"DBus connection broken: {ex}; try restarting `bluetooth` and `dbus`"
|
||||
) from ex
|
||||
except FileNotFoundError as ex:
|
||||
self._cancel_device_detected()
|
||||
_LOGGER.debug(
|
||||
"FileNotFoundError while starting bluetooth: %s", ex, exc_info=True
|
||||
)
|
||||
if is_docker_env():
|
||||
raise ConfigEntryNotReady(
|
||||
f"DBus service not found; docker config may be missing `-v /run/dbus:/run/dbus:ro`: {ex}"
|
||||
) from ex
|
||||
raise ConfigEntryNotReady(
|
||||
f"DBus service not found; make sure the DBus socket is available to Home Assistant: {ex}"
|
||||
) from ex
|
||||
except asyncio.TimeoutError as ex:
|
||||
self._cancel_device_detected()
|
||||
raise ConfigEntryNotReady(
|
||||
f"Timed out starting Bluetooth after {START_TIMEOUT} seconds"
|
||||
) from ex
|
||||
except (FileNotFoundError, BleakError) as ex:
|
||||
except BleakError as ex:
|
||||
self._cancel_device_detected()
|
||||
_LOGGER.debug("BleakError while starting bluetooth: %s", ex, exc_info=True)
|
||||
raise ConfigEntryNotReady(f"Failed to start Bluetooth: {ex}") from ex
|
||||
self.async_setup_unavailable_tracking()
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop)
|
||||
self._async_setup_scanner_watchdog()
|
||||
self._cancel_stop = self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP, self._async_hass_stopping
|
||||
)
|
||||
|
||||
@hass_callback
|
||||
def _async_setup_scanner_watchdog(self) -> None:
|
||||
"""If Dbus gets restarted or updated, we need to restart the scanner."""
|
||||
self._last_detection = MONOTONIC_TIME()
|
||||
self._cancel_watchdog = async_track_time_interval(
|
||||
self.hass, self._async_scanner_watchdog, SCANNER_WATCHDOG_INTERVAL
|
||||
)
|
||||
|
||||
async def _async_scanner_watchdog(self, now: datetime) -> None:
|
||||
"""Check if the scanner is running."""
|
||||
time_since_last_detection = MONOTONIC_TIME() - self._last_detection
|
||||
if time_since_last_detection < SCANNER_WATCHDOG_TIMEOUT:
|
||||
return
|
||||
_LOGGER.info(
|
||||
"Bluetooth scanner has gone quiet for %s, restarting",
|
||||
SCANNER_WATCHDOG_INTERVAL,
|
||||
)
|
||||
async with self.start_stop_lock:
|
||||
self.async_start_reload()
|
||||
await self.async_stop()
|
||||
await self.async_start(self._scanning_mode, self._adapter)
|
||||
|
||||
@hass_callback
|
||||
def async_setup_unavailable_tracking(self) -> None:
|
||||
@@ -378,6 +455,7 @@ class BluetoothManager:
|
||||
self, device: BLEDevice, advertisement_data: AdvertisementData
|
||||
) -> None:
|
||||
"""Handle a detected device."""
|
||||
self._last_detection = MONOTONIC_TIME()
|
||||
matched_domains = self._integration_matcher.match_domains(
|
||||
device, advertisement_data
|
||||
)
|
||||
@@ -490,17 +568,29 @@ class BluetoothManager:
|
||||
for device_adv in self.scanner.history.values()
|
||||
]
|
||||
|
||||
async def async_stop(self, event: Event | None = None) -> None:
|
||||
async def _async_hass_stopping(self, event: Event) -> None:
|
||||
"""Stop the Bluetooth integration at shutdown."""
|
||||
self._cancel_stop = None
|
||||
await self.async_stop()
|
||||
|
||||
async def async_stop(self) -> None:
|
||||
"""Stop bluetooth discovery."""
|
||||
_LOGGER.debug("Stopping bluetooth discovery")
|
||||
if self._cancel_watchdog:
|
||||
self._cancel_watchdog()
|
||||
self._cancel_watchdog = None
|
||||
if self._cancel_device_detected:
|
||||
self._cancel_device_detected()
|
||||
self._cancel_device_detected = None
|
||||
if self._cancel_unavailable_tracking:
|
||||
self._cancel_unavailable_tracking()
|
||||
self._cancel_unavailable_tracking = None
|
||||
if self._cancel_stop:
|
||||
self._cancel_stop()
|
||||
self._cancel_stop = None
|
||||
if self.scanner:
|
||||
try:
|
||||
await self.scanner.stop()
|
||||
await self.scanner.stop() # type: ignore[no-untyped-call]
|
||||
except BleakError as ex:
|
||||
# This is not fatal, and they may want to reload
|
||||
# the config entry to restart the scanner if they
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
"""Config flow to configure the Bluetooth integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import onboarding
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import CONF_ADAPTER, DEFAULT_NAME, DOMAIN
|
||||
from .util import async_get_bluetooth_adapters
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
|
||||
class BluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Config flow for Bluetooth."""
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/bluetooth",
|
||||
"dependencies": ["websocket_api"],
|
||||
"quality_scale": "internal",
|
||||
"requirements": ["bleak==0.14.3", "bluetooth-adapters==0.1.2"],
|
||||
"requirements": ["bleak==0.15.1", "bluetooth-adapters==0.1.3"],
|
||||
"codeowners": ["@bdraco"],
|
||||
"config_flow": true,
|
||||
"iot_class": "local_push"
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
"""The bluetooth integration matchers."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from dataclasses import dataclass
|
||||
import fnmatch
|
||||
from typing import Final, TypedDict
|
||||
from typing import TYPE_CHECKING, Final, TypedDict
|
||||
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from lru import LRU # pylint: disable=no-name-in-module
|
||||
|
||||
from homeassistant.loader import BluetoothMatcher, BluetoothMatcherOptional
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
|
||||
|
||||
MAX_REMEMBER_ADDRESSES: Final = 2048
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import contextlib
|
||||
import logging
|
||||
from typing import Any, Final, cast
|
||||
from typing import TYPE_CHECKING, Any, Final
|
||||
|
||||
from bleak import BleakScanner
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import (
|
||||
AdvertisementData,
|
||||
AdvertisementDataCallback,
|
||||
@@ -16,6 +15,10 @@ from bleak.backends.scanner import (
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, callback as hass_callback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from bleak.backends.device import BLEDevice
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
FILTER_UUIDS: Final = "UUIDs"
|
||||
@@ -32,7 +35,7 @@ def _dispatch_callback(
|
||||
"""Dispatch the callback."""
|
||||
if not callback:
|
||||
# Callback destroyed right before being called, ignore
|
||||
return
|
||||
return # type: ignore[unreachable]
|
||||
|
||||
if (uuids := filters.get(FILTER_UUIDS)) and not uuids.intersection(
|
||||
advertisement_data.service_uuids
|
||||
@@ -45,7 +48,7 @@ def _dispatch_callback(
|
||||
_LOGGER.exception("Error in callback: %s", callback)
|
||||
|
||||
|
||||
class HaBleakScanner(BleakScanner): # type: ignore[misc]
|
||||
class HaBleakScanner(BleakScanner):
|
||||
"""BleakScanner that cannot be stopped."""
|
||||
|
||||
def __init__( # pylint: disable=super-init-not-called
|
||||
@@ -106,16 +109,29 @@ class HaBleakScanner(BleakScanner): # type: ignore[misc]
|
||||
_dispatch_callback(*callback_filters, device, advertisement_data)
|
||||
|
||||
|
||||
class HaBleakScannerWrapper(BaseBleakScanner): # type: ignore[misc]
|
||||
class HaBleakScannerWrapper(BaseBleakScanner):
|
||||
"""A wrapper that uses the single instance."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
*args: Any,
|
||||
detection_callback: AdvertisementDataCallback | None = None,
|
||||
service_uuids: list[str] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Initialize the BleakScanner."""
|
||||
self._detection_cancel: CALLBACK_TYPE | None = None
|
||||
self._mapped_filters: dict[str, set[str]] = {}
|
||||
self._adv_data_callback: AdvertisementDataCallback | None = None
|
||||
self._map_filters(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
remapped_kwargs = {
|
||||
"detection_callback": detection_callback,
|
||||
"service_uuids": service_uuids or [],
|
||||
**kwargs,
|
||||
}
|
||||
self._map_filters(*args, **remapped_kwargs)
|
||||
super().__init__(
|
||||
detection_callback=detection_callback, service_uuids=service_uuids or []
|
||||
)
|
||||
|
||||
async def stop(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Stop scanning for devices."""
|
||||
@@ -153,9 +169,11 @@ class HaBleakScannerWrapper(BaseBleakScanner): # type: ignore[misc]
|
||||
def discovered_devices(self) -> list[BLEDevice]:
|
||||
"""Return a list of discovered devices."""
|
||||
assert HA_BLEAK_SCANNER is not None
|
||||
return cast(list[BLEDevice], HA_BLEAK_SCANNER.discovered_devices)
|
||||
return HA_BLEAK_SCANNER.discovered_devices
|
||||
|
||||
def register_detection_callback(self, callback: AdvertisementDataCallback) -> None:
|
||||
def register_detection_callback(
|
||||
self, callback: AdvertisementDataCallback | None
|
||||
) -> None:
|
||||
"""Register a callback that is called when a device is discovered or has a property changed.
|
||||
|
||||
This method takes the callback and registers it with the long running
|
||||
@@ -171,6 +189,7 @@ class HaBleakScannerWrapper(BaseBleakScanner): # type: ignore[misc]
|
||||
self._cancel_callback()
|
||||
super().register_detection_callback(self._adv_data_callback)
|
||||
assert HA_BLEAK_SCANNER is not None
|
||||
assert self._callback is not None
|
||||
self._detection_cancel = HA_BLEAK_SCANNER.async_register_callback(
|
||||
self._callback, self._mapped_filters
|
||||
)
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
"""Passive update coordinator for the Bluetooth integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Generator
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import BluetoothChange
|
||||
from .update_coordinator import BasePassiveBluetoothCoordinator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable, Generator
|
||||
import logging
|
||||
|
||||
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
|
||||
|
||||
|
||||
class PassiveBluetoothDataUpdateCoordinator(BasePassiveBluetoothCoordinator):
|
||||
"""Class to manage passive bluetooth advertisements.
|
||||
@@ -25,9 +27,10 @@ class PassiveBluetoothDataUpdateCoordinator(BasePassiveBluetoothCoordinator):
|
||||
hass: HomeAssistant,
|
||||
logger: logging.Logger,
|
||||
address: str,
|
||||
mode: BluetoothScanningMode,
|
||||
) -> None:
|
||||
"""Initialize PassiveBluetoothDataUpdateCoordinator."""
|
||||
super().__init__(hass, logger, address)
|
||||
super().__init__(hass, logger, address, mode)
|
||||
self._listeners: dict[CALLBACK_TYPE, tuple[CALLBACK_TYPE, object | None]] = {}
|
||||
|
||||
@callback
|
||||
@@ -65,7 +68,7 @@ class PassiveBluetoothDataUpdateCoordinator(BasePassiveBluetoothCoordinator):
|
||||
@callback
|
||||
def _async_handle_bluetooth_event(
|
||||
self,
|
||||
service_info: BluetoothServiceInfo,
|
||||
service_info: BluetoothServiceInfoBleak,
|
||||
change: BluetoothChange,
|
||||
) -> None:
|
||||
"""Handle a Bluetooth event."""
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
"""Passive update processors for the Bluetooth integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Mapping
|
||||
import dataclasses
|
||||
import logging
|
||||
from typing import Any, Generic, TypeVar
|
||||
|
||||
from home_assistant_bluetooth import BluetoothServiceInfo
|
||||
from typing import TYPE_CHECKING, Any, Generic, TypeVar
|
||||
|
||||
from homeassistant.const import ATTR_IDENTIFIERS, ATTR_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import BluetoothChange
|
||||
from .const import DOMAIN
|
||||
from .update_coordinator import BasePassiveBluetoothCoordinator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable, Mapping
|
||||
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import BluetoothChange, BluetoothScanningMode, BluetoothServiceInfoBleak
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class PassiveBluetoothEntityKey:
|
||||
@@ -62,9 +64,10 @@ class PassiveBluetoothProcessorCoordinator(BasePassiveBluetoothCoordinator):
|
||||
hass: HomeAssistant,
|
||||
logger: logging.Logger,
|
||||
address: str,
|
||||
mode: BluetoothScanningMode,
|
||||
) -> None:
|
||||
"""Initialize the coordinator."""
|
||||
super().__init__(hass, logger, address)
|
||||
super().__init__(hass, logger, address, mode)
|
||||
self._processors: list[PassiveBluetoothDataProcessor] = []
|
||||
|
||||
@callback
|
||||
@@ -92,7 +95,7 @@ class PassiveBluetoothProcessorCoordinator(BasePassiveBluetoothCoordinator):
|
||||
@callback
|
||||
def _async_handle_bluetooth_event(
|
||||
self,
|
||||
service_info: BluetoothServiceInfo,
|
||||
service_info: BluetoothServiceInfoBleak,
|
||||
change: BluetoothChange,
|
||||
) -> None:
|
||||
"""Handle a Bluetooth event."""
|
||||
@@ -122,7 +125,7 @@ class PassiveBluetoothDataProcessor(Generic[_T]):
|
||||
The processor will call the update_method every time the bluetooth device
|
||||
receives a new advertisement data from the coordinator with the following signature:
|
||||
|
||||
update_method(service_info: BluetoothServiceInfo) -> PassiveBluetoothDataUpdate
|
||||
update_method(service_info: BluetoothServiceInfoBleak) -> PassiveBluetoothDataUpdate
|
||||
|
||||
As the size of each advertisement is limited, the update_method should
|
||||
return a PassiveBluetoothDataUpdate object that contains only data that
|
||||
@@ -135,7 +138,9 @@ class PassiveBluetoothDataProcessor(Generic[_T]):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
update_method: Callable[[BluetoothServiceInfo], PassiveBluetoothDataUpdate[_T]],
|
||||
update_method: Callable[
|
||||
[BluetoothServiceInfoBleak], PassiveBluetoothDataUpdate[_T]
|
||||
],
|
||||
) -> None:
|
||||
"""Initialize the coordinator."""
|
||||
self.coordinator: PassiveBluetoothProcessorCoordinator
|
||||
@@ -241,7 +246,7 @@ class PassiveBluetoothDataProcessor(Generic[_T]):
|
||||
@callback
|
||||
def async_handle_bluetooth_event(
|
||||
self,
|
||||
service_info: BluetoothServiceInfo,
|
||||
service_info: BluetoothServiceInfoBleak,
|
||||
change: BluetoothChange,
|
||||
) -> None:
|
||||
"""Handle a Bluetooth event."""
|
||||
|
||||
@@ -4,13 +4,13 @@ from __future__ import annotations
|
||||
import logging
|
||||
import time
|
||||
|
||||
from home_assistant_bluetooth import BluetoothServiceInfo
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
|
||||
from . import (
|
||||
BluetoothCallbackMatcher,
|
||||
BluetoothChange,
|
||||
BluetoothScanningMode,
|
||||
BluetoothServiceInfoBleak,
|
||||
async_register_callback,
|
||||
async_track_unavailable,
|
||||
)
|
||||
@@ -27,6 +27,7 @@ class BasePassiveBluetoothCoordinator:
|
||||
hass: HomeAssistant,
|
||||
logger: logging.Logger,
|
||||
address: str,
|
||||
mode: BluetoothScanningMode,
|
||||
) -> None:
|
||||
"""Initialize the coordinator."""
|
||||
self.hass = hass
|
||||
@@ -36,6 +37,7 @@ class BasePassiveBluetoothCoordinator:
|
||||
self._cancel_track_unavailable: CALLBACK_TYPE | None = None
|
||||
self._cancel_bluetooth_advertisements: CALLBACK_TYPE | None = None
|
||||
self._present = False
|
||||
self.mode = mode
|
||||
self.last_seen = 0.0
|
||||
|
||||
@callback
|
||||
@@ -61,6 +63,7 @@ class BasePassiveBluetoothCoordinator:
|
||||
self.hass,
|
||||
self._async_handle_bluetooth_event,
|
||||
BluetoothCallbackMatcher(address=self.address),
|
||||
self.mode,
|
||||
)
|
||||
self._cancel_track_unavailable = async_track_unavailable(
|
||||
self.hass,
|
||||
@@ -86,7 +89,7 @@ class BasePassiveBluetoothCoordinator:
|
||||
@callback
|
||||
def _async_handle_bluetooth_event(
|
||||
self,
|
||||
service_info: BluetoothServiceInfo,
|
||||
service_info: BluetoothServiceInfoBleak,
|
||||
change: BluetoothChange,
|
||||
) -> None:
|
||||
"""Handle a Bluetooth event."""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""bluetooth usage utility to handle multiple instances."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import bleak
|
||||
@@ -10,9 +11,9 @@ ORIGINAL_BLEAK_SCANNER = bleak.BleakScanner
|
||||
|
||||
def install_multiple_bleak_catcher() -> None:
|
||||
"""Wrap the bleak classes to return the shared instance if multiple instances are detected."""
|
||||
bleak.BleakScanner = HaBleakScannerWrapper
|
||||
bleak.BleakScanner = HaBleakScannerWrapper # type: ignore[misc, assignment]
|
||||
|
||||
|
||||
def uninstall_multiple_bleak_catcher() -> None:
|
||||
"""Unwrap the bleak classes."""
|
||||
bleak.BleakScanner = ORIGINAL_BLEAK_SCANNER
|
||||
bleak.BleakScanner = ORIGINAL_BLEAK_SCANNER # type: ignore[misc]
|
||||
|
||||
@@ -8,7 +8,6 @@ import logging
|
||||
from uuid import UUID
|
||||
|
||||
from bleak import BleakClient, BleakError
|
||||
from bleak.backends.device import BLEDevice
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
@@ -136,15 +135,12 @@ async def async_setup_scanner( # noqa: C901
|
||||
async def _async_see_update_ble_battery(
|
||||
mac: str,
|
||||
now: datetime,
|
||||
service_info: bluetooth.BluetoothServiceInfo,
|
||||
service_info: bluetooth.BluetoothServiceInfoBleak,
|
||||
) -> None:
|
||||
"""Lookup Bluetooth LE devices and update status."""
|
||||
battery = None
|
||||
ble_device: BLEDevice | str = (
|
||||
bluetooth.async_ble_device_from_address(hass, mac) or mac
|
||||
)
|
||||
try:
|
||||
async with BleakClient(ble_device) as client:
|
||||
async with BleakClient(service_info.device) as client:
|
||||
bat_char = await client.read_gatt_char(BATTERY_CHARACTERISTIC_UUID)
|
||||
battery = ord(bat_char)
|
||||
except asyncio.TimeoutError:
|
||||
@@ -165,7 +161,8 @@ async def async_setup_scanner( # noqa: C901
|
||||
|
||||
@callback
|
||||
def _async_update_ble(
|
||||
service_info: bluetooth.BluetoothServiceInfo, change: bluetooth.BluetoothChange
|
||||
service_info: bluetooth.BluetoothServiceInfoBleak,
|
||||
change: bluetooth.BluetoothChange,
|
||||
) -> None:
|
||||
"""Update from a ble callback."""
|
||||
mac = service_info.address
|
||||
@@ -199,7 +196,9 @@ async def async_setup_scanner( # noqa: C901
|
||||
_async_update_ble(service_info, bluetooth.BluetoothChange.ADVERTISEMENT)
|
||||
|
||||
cancels = [
|
||||
bluetooth.async_register_callback(hass, _async_update_ble, None),
|
||||
bluetooth.async_register_callback(
|
||||
hass, _async_update_ble, None, bluetooth.BluetoothScanningMode.ACTIVE
|
||||
),
|
||||
async_track_time_interval(hass, _async_refresh_ble, interval),
|
||||
]
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class BMWNotificationService(BaseNotificationService):
|
||||
"""Set up the notification service."""
|
||||
self.targets: dict[str, MyBMWVehicle] = targets
|
||||
|
||||
def send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||
async def async_send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||
"""Send a message or POI to the car."""
|
||||
for vehicle in kwargs[ATTR_TARGET]:
|
||||
vehicle = cast(MyBMWVehicle, vehicle)
|
||||
@@ -81,6 +81,6 @@ class BMWNotificationService(BaseNotificationService):
|
||||
}
|
||||
)
|
||||
|
||||
vehicle.remote_services.trigger_send_poi(location_dict)
|
||||
await vehicle.remote_services.trigger_send_poi(location_dict)
|
||||
else:
|
||||
raise ValueError(f"'data.{ATTR_LOCATION}' is required.")
|
||||
|
||||
@@ -26,11 +26,13 @@ from homeassistant.const import (
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import BroadlinkDevice
|
||||
from .const import DOMAIN
|
||||
from .entity import BroadlinkEntity
|
||||
from .helpers import data_packet, import_device, mac_address
|
||||
@@ -80,8 +82,18 @@ async def async_setup_platform(
|
||||
host = config.get(CONF_HOST)
|
||||
|
||||
if switches := config.get(CONF_SWITCHES):
|
||||
platform_data = hass.data[DOMAIN].platforms.setdefault(Platform.SWITCH, {})
|
||||
platform_data.setdefault(mac_addr, []).extend(switches)
|
||||
platform_data = hass.data[DOMAIN].platforms.get(Platform.SWITCH, {})
|
||||
async_add_entities_config_entry: AddEntitiesCallback
|
||||
device: BroadlinkDevice
|
||||
async_add_entities_config_entry, device = platform_data.get(
|
||||
mac_addr, (None, None)
|
||||
)
|
||||
if not async_add_entities_config_entry:
|
||||
raise PlatformNotReady
|
||||
|
||||
async_add_entities_config_entry(
|
||||
BroadlinkRMSwitch(device, config) for config in switches
|
||||
)
|
||||
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
@@ -104,12 +116,8 @@ async def async_setup_entry(
|
||||
switches: list[BroadlinkSwitch] = []
|
||||
|
||||
if device.api.type in {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"}:
|
||||
platform_data = hass.data[DOMAIN].platforms.get(Platform.SWITCH, {})
|
||||
user_defined_switches = platform_data.get(device.api.mac, {})
|
||||
switches.extend(
|
||||
BroadlinkRMSwitch(device, config) for config in user_defined_switches
|
||||
)
|
||||
|
||||
platform_data = hass.data[DOMAIN].platforms.setdefault(Platform.SWITCH, {})
|
||||
platform_data[device.api.mac] = async_add_entities, device
|
||||
elif device.api.type == "SP1":
|
||||
switches.append(BroadlinkSP1Switch(device))
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import os
|
||||
from random import SystemRandom
|
||||
from typing import Final, Optional, cast, final
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp import hdrs, web
|
||||
import async_timeout
|
||||
import attr
|
||||
import voluptuous as vol
|
||||
@@ -715,8 +715,11 @@ class CameraView(HomeAssistantView):
|
||||
)
|
||||
|
||||
if not authenticated:
|
||||
if request[KEY_AUTHENTICATED]:
|
||||
# Attempt with invalid bearer token, raise unauthorized
|
||||
# so ban middleware can handle it.
|
||||
if hdrs.AUTHORIZATION in request.headers:
|
||||
raise web.HTTPUnauthorized()
|
||||
# Invalid sigAuth or camera access token
|
||||
raise web.HTTPForbidden()
|
||||
|
||||
if not camera.is_on:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "deCONZ",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/deconz",
|
||||
"requirements": ["pydeconz==100"],
|
||||
"requirements": ["pydeconz==102"],
|
||||
"ssdp": [
|
||||
{
|
||||
"manufacturer": "Royal Philips Electronics",
|
||||
|
||||
@@ -40,7 +40,11 @@ GAS_USAGE_DEVICE_CLASSES = (
|
||||
sensor.SensorDeviceClass.GAS,
|
||||
)
|
||||
GAS_USAGE_UNITS = {
|
||||
sensor.SensorDeviceClass.ENERGY: (ENERGY_WATT_HOUR, ENERGY_KILO_WATT_HOUR),
|
||||
sensor.SensorDeviceClass.ENERGY: (
|
||||
ENERGY_WATT_HOUR,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
ENERGY_MEGA_WATT_HOUR,
|
||||
),
|
||||
sensor.SensorDeviceClass.GAS: (VOLUME_CUBIC_METERS, VOLUME_CUBIC_FEET),
|
||||
}
|
||||
GAS_PRICE_UNITS = tuple(
|
||||
|
||||
@@ -5,12 +5,14 @@ from enocean.utils import combine_hex
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
||||
from homeassistant.const import CONF_ID, CONF_NAME
|
||||
from homeassistant.const import CONF_ID, CONF_NAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN, LOGGER
|
||||
from .device import EnOceanEntity
|
||||
|
||||
CONF_CHANNEL = "channel"
|
||||
@@ -25,10 +27,40 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(
|
||||
def generate_unique_id(dev_id: list[int], channel: int) -> str:
|
||||
"""Generate a valid unique id."""
|
||||
return f"{combine_hex(dev_id)}-{channel}"
|
||||
|
||||
|
||||
def _migrate_to_new_unique_id(hass: HomeAssistant, dev_id, channel) -> None:
|
||||
"""Migrate old unique ids to new unique ids."""
|
||||
old_unique_id = f"{combine_hex(dev_id)}"
|
||||
|
||||
ent_reg = entity_registry.async_get(hass)
|
||||
entity_id = ent_reg.async_get_entity_id(Platform.SWITCH, DOMAIN, old_unique_id)
|
||||
|
||||
if entity_id is not None:
|
||||
new_unique_id = generate_unique_id(dev_id, channel)
|
||||
try:
|
||||
ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)
|
||||
except ValueError:
|
||||
LOGGER.warning(
|
||||
"Skip migration of id [%s] to [%s] because it already exists",
|
||||
old_unique_id,
|
||||
new_unique_id,
|
||||
)
|
||||
else:
|
||||
LOGGER.debug(
|
||||
"Migrating unique_id from [%s] to [%s]",
|
||||
old_unique_id,
|
||||
new_unique_id,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the EnOcean switch platform."""
|
||||
@@ -36,7 +68,8 @@ def setup_platform(
|
||||
dev_id = config.get(CONF_ID)
|
||||
dev_name = config.get(CONF_NAME)
|
||||
|
||||
add_entities([EnOceanSwitch(dev_id, dev_name, channel)])
|
||||
_migrate_to_new_unique_id(hass, dev_id, channel)
|
||||
async_add_entities([EnOceanSwitch(dev_id, dev_name, channel)])
|
||||
|
||||
|
||||
class EnOceanSwitch(EnOceanEntity, SwitchEntity):
|
||||
@@ -49,7 +82,7 @@ class EnOceanSwitch(EnOceanEntity, SwitchEntity):
|
||||
self._on_state = False
|
||||
self._on_state2 = False
|
||||
self.channel = channel
|
||||
self._attr_unique_id = f"{combine_hex(dev_id)}"
|
||||
self._attr_unique_id = generate_unique_id(dev_id, channel)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "entur_public_transport",
|
||||
"name": "Entur",
|
||||
"documentation": "https://www.home-assistant.io/integrations/entur_public_transport",
|
||||
"requirements": ["enturclient==0.2.3"],
|
||||
"requirements": ["enturclient==0.2.4"],
|
||||
"codeowners": ["@hfurubotten"],
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["enturclient"]
|
||||
|
||||
@@ -128,26 +128,17 @@ class EvoClimateEntity(EvoDevice, ClimateEntity):
|
||||
|
||||
_attr_temperature_unit = TEMP_CELSIUS
|
||||
|
||||
def __init__(self, evo_broker, evo_device) -> None:
|
||||
"""Initialize a Climate device."""
|
||||
super().__init__(evo_broker, evo_device)
|
||||
|
||||
self._preset_modes = None
|
||||
|
||||
@property
|
||||
def hvac_modes(self) -> list[str]:
|
||||
"""Return a list of available hvac operation modes."""
|
||||
return list(HA_HVAC_TO_TCS)
|
||||
|
||||
@property
|
||||
def preset_modes(self) -> list[str] | None:
|
||||
"""Return a list of available preset modes."""
|
||||
return self._preset_modes
|
||||
|
||||
|
||||
class EvoZone(EvoChild, EvoClimateEntity):
|
||||
"""Base for a Honeywell TCC Zone."""
|
||||
|
||||
_attr_preset_modes = list(HA_PRESET_TO_EVO)
|
||||
|
||||
def __init__(self, evo_broker, evo_device) -> None:
|
||||
"""Initialize a Honeywell TCC Zone."""
|
||||
super().__init__(evo_broker, evo_device)
|
||||
@@ -233,7 +224,7 @@ class EvoZone(EvoChild, EvoClimateEntity):
|
||||
"""
|
||||
return self._evo_device.setpointCapabilities["maxHeatSetpoint"]
|
||||
|
||||
async def async_set_temperature(self, **kwargs) -> None:
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set a new target temperature."""
|
||||
temperature = kwargs["temperature"]
|
||||
|
||||
@@ -249,7 +240,7 @@ class EvoZone(EvoChild, EvoClimateEntity):
|
||||
self._evo_device.set_temperature(temperature, until=until)
|
||||
)
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set a Zone to one of its native EVO_* operating modes.
|
||||
|
||||
Zones inherit their _effective_ operating mode from their Controller.
|
||||
@@ -387,7 +378,7 @@ class EvoController(EvoClimateEntity):
|
||||
"""Return the current preset mode, e.g., home, away, temp."""
|
||||
return TCS_PRESET_TO_HA.get(self._evo_tcs.systemModeStatus["mode"])
|
||||
|
||||
async def async_set_temperature(self, **kwargs) -> None:
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Raise exception as Controllers don't have a target temperature."""
|
||||
raise NotImplementedError("Evohome Controllers don't have target temperatures.")
|
||||
|
||||
|
||||
@@ -6,14 +6,19 @@ from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from bleak import BleakScanner
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from fjaraskupan import Device, State, device_filter
|
||||
from fjaraskupan import Device, State
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
BluetoothCallbackMatcher,
|
||||
BluetoothChange,
|
||||
BluetoothScanningMode,
|
||||
BluetoothServiceInfoBleak,
|
||||
async_address_present,
|
||||
async_register_callback,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
@@ -66,16 +71,18 @@ class Coordinator(DataUpdateCoordinator[State]):
|
||||
async def _async_update_data(self) -> State:
|
||||
"""Handle an explicit update request."""
|
||||
if self._refresh_was_scheduled:
|
||||
raise UpdateFailed("No data received within schedule.")
|
||||
if async_address_present(self.hass, self.device.address):
|
||||
return self.device.state
|
||||
raise UpdateFailed(
|
||||
"No data received within schedule, and device is no longer present"
|
||||
)
|
||||
|
||||
await self.device.update()
|
||||
return self.device.state
|
||||
|
||||
def detection_callback(
|
||||
self, ble_device: BLEDevice, advertisement_data: AdvertisementData
|
||||
) -> None:
|
||||
def detection_callback(self, service_info: BluetoothServiceInfoBleak) -> None:
|
||||
"""Handle a new announcement of data."""
|
||||
self.device.detection_callback(ble_device, advertisement_data)
|
||||
self.device.detection_callback(service_info.device, service_info.advertisement)
|
||||
self.async_set_updated_data(self.device.state)
|
||||
|
||||
|
||||
@@ -83,59 +90,52 @@ class Coordinator(DataUpdateCoordinator[State]):
|
||||
class EntryState:
|
||||
"""Store state of config entry."""
|
||||
|
||||
scanner: BleakScanner
|
||||
coordinators: dict[str, Coordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Fjäråskupan from a config entry."""
|
||||
|
||||
scanner = BleakScanner(filters={"DuplicateData": True})
|
||||
|
||||
state = EntryState(scanner, {})
|
||||
state = EntryState({})
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = state
|
||||
|
||||
async def detection_callback(
|
||||
ble_device: BLEDevice, advertisement_data: AdvertisementData
|
||||
def detection_callback(
|
||||
service_info: BluetoothServiceInfoBleak, change: BluetoothChange
|
||||
) -> None:
|
||||
if data := state.coordinators.get(ble_device.address):
|
||||
_LOGGER.debug(
|
||||
"Update: %s %s - %s", ble_device.name, ble_device, advertisement_data
|
||||
)
|
||||
|
||||
data.detection_callback(ble_device, advertisement_data)
|
||||
if change != BluetoothChange.ADVERTISEMENT:
|
||||
return
|
||||
if data := state.coordinators.get(service_info.address):
|
||||
_LOGGER.debug("Update: %s", service_info)
|
||||
data.detection_callback(service_info)
|
||||
else:
|
||||
if not device_filter(ble_device, advertisement_data):
|
||||
return
|
||||
_LOGGER.debug("Detected: %s", service_info)
|
||||
|
||||
_LOGGER.debug(
|
||||
"Detected: %s %s - %s", ble_device.name, ble_device, advertisement_data
|
||||
)
|
||||
|
||||
device = Device(ble_device)
|
||||
device = Device(service_info.device)
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, ble_device.address)},
|
||||
identifiers={(DOMAIN, service_info.address)},
|
||||
manufacturer="Fjäråskupan",
|
||||
name="Fjäråskupan",
|
||||
)
|
||||
|
||||
coordinator: Coordinator = Coordinator(hass, device, device_info)
|
||||
coordinator.detection_callback(ble_device, advertisement_data)
|
||||
coordinator.detection_callback(service_info)
|
||||
|
||||
state.coordinators[ble_device.address] = coordinator
|
||||
state.coordinators[service_info.address] = coordinator
|
||||
async_dispatcher_send(
|
||||
hass, f"{DISPATCH_DETECTION}.{entry.entry_id}", coordinator
|
||||
)
|
||||
|
||||
scanner.register_detection_callback(detection_callback)
|
||||
await scanner.start()
|
||||
|
||||
async def on_hass_stop(event: Event) -> None:
|
||||
await scanner.stop()
|
||||
|
||||
entry.async_on_unload(
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop)
|
||||
async_register_callback(
|
||||
hass,
|
||||
detection_callback,
|
||||
BluetoothCallbackMatcher(
|
||||
manufacturer_id=20296,
|
||||
manufacturer_data_start=[79, 68, 70, 74, 65, 82],
|
||||
),
|
||||
BluetoothScanningMode.ACTIVE,
|
||||
)
|
||||
)
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
@@ -173,7 +173,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
entry_state: EntryState = hass.data[DOMAIN].pop(entry.entry_id)
|
||||
await entry_state.scanner.stop()
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
|
||||
@@ -1,42 +1,25 @@
|
||||
"""Config flow for Fjäråskupan integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import async_timeout
|
||||
from bleak import BleakScanner
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
from fjaraskupan import device_filter
|
||||
|
||||
from homeassistant.components.bluetooth import async_discovered_service_info
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.config_entry_flow import register_discovery_flow
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
CONST_WAIT_TIME = 5.0
|
||||
|
||||
|
||||
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
||||
"""Return if there are devices that can be discovered."""
|
||||
|
||||
event = asyncio.Event()
|
||||
service_infos = async_discovered_service_info(hass)
|
||||
|
||||
def detection(device: BLEDevice, advertisement_data: AdvertisementData):
|
||||
if device_filter(device, advertisement_data):
|
||||
event.set()
|
||||
for service_info in service_infos:
|
||||
if device_filter(service_info.device, service_info.advertisement):
|
||||
return True
|
||||
|
||||
async with BleakScanner(
|
||||
detection_callback=detection,
|
||||
filters={"DuplicateData": True},
|
||||
):
|
||||
try:
|
||||
async with async_timeout.timeout(CONST_WAIT_TIME):
|
||||
await event.wait()
|
||||
except asyncio.TimeoutError:
|
||||
return False
|
||||
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
register_discovery_flow(DOMAIN, "Fjäråskupan", _async_has_devices)
|
||||
|
||||
@@ -6,5 +6,12 @@
|
||||
"requirements": ["fjaraskupan==1.0.2"],
|
||||
"codeowners": ["@elupus"],
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["bleak", "fjaraskupan"]
|
||||
"loggers": ["bleak", "fjaraskupan"],
|
||||
"dependencies": ["bluetooth"],
|
||||
"bluetooth": [
|
||||
{
|
||||
"manufacturer_id": 20296,
|
||||
"manufacturer_data_start": [79, 68, 70, 74, 65, 82]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Any
|
||||
from pyflunearyou import Client
|
||||
from pyflunearyou.errors import FluNearYouError
|
||||
|
||||
from homeassistant.components.repairs import IssueSeverity, async_create_issue
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -26,6 +27,15 @@ PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Flu Near You as config entry."""
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"integration_removal",
|
||||
is_fixable=True,
|
||||
severity=IssueSeverity.ERROR,
|
||||
translation_key="integration_removal",
|
||||
)
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(hass)
|
||||
client = Client(session=websession)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"name": "Flu Near You",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/flunearyou",
|
||||
"dependencies": ["repairs"],
|
||||
"requirements": ["pyflunearyou==2.0.2"],
|
||||
"codeowners": ["@bachya"],
|
||||
"iot_class": "cloud_polling",
|
||||
|
||||
42
homeassistant/components/flunearyou/repairs.py
Normal file
42
homeassistant/components/flunearyou/repairs.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Repairs platform for the Flu Near You integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.repairs import RepairsFlow
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class FluNearYouFixFlow(RepairsFlow):
|
||||
"""Handler for an issue fixing flow."""
|
||||
|
||||
async def async_step_init(
|
||||
self, user_input: dict[str, str] | None = None
|
||||
) -> data_entry_flow.FlowResult:
|
||||
"""Handle the first step of a fix flow."""
|
||||
return await self.async_step_confirm()
|
||||
|
||||
async def async_step_confirm(
|
||||
self, user_input: dict[str, str] | None = None
|
||||
) -> data_entry_flow.FlowResult:
|
||||
"""Handle the confirm step of a fix flow."""
|
||||
if user_input is not None:
|
||||
removal_tasks = [
|
||||
self.hass.config_entries.async_remove(entry.entry_id)
|
||||
for entry in self.hass.config_entries.async_entries(DOMAIN)
|
||||
]
|
||||
await asyncio.gather(*removal_tasks)
|
||||
return self.async_create_entry(title="Fixed issue", data={})
|
||||
return self.async_show_form(step_id="confirm", data_schema=vol.Schema({}))
|
||||
|
||||
|
||||
async def async_create_fix_flow(
|
||||
hass: HomeAssistant, issue_id: str
|
||||
) -> FluNearYouFixFlow:
|
||||
"""Create flow."""
|
||||
return FluNearYouFixFlow()
|
||||
@@ -16,5 +16,18 @@
|
||||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_location%]"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"integration_removal": {
|
||||
"title": "Flu Near You is no longer available",
|
||||
"fix_flow": {
|
||||
"step": {
|
||||
"confirm": {
|
||||
"title": "Remove Flu Near You",
|
||||
"description": "The external data source powering the Flu Near You integration is no longer available; thus, the integration no longer works.\n\nPress SUBMIT to remove Flu Near You from your Home Assistant instance."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,18 @@
|
||||
"title": "Configure Flu Near You"
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"integration_removal": {
|
||||
"fix_flow": {
|
||||
"step": {
|
||||
"confirm": {
|
||||
"description": "The data source that powered the Flu Near You integration is no longer available. Press SUBMIT to remove all configured instances of the integration from Home Assistant.",
|
||||
"title": "Remove Flu Near You"
|
||||
}
|
||||
}
|
||||
},
|
||||
"title": "Flu Near You is no longer available"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,27 +105,33 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
assert mac_address is not None
|
||||
mac = dr.format_mac(mac_address)
|
||||
await self.async_set_unique_id(mac)
|
||||
for entry in self._async_current_entries(include_ignore=False):
|
||||
if entry.data[CONF_HOST] == device[ATTR_IPADDR] or (
|
||||
entry.unique_id
|
||||
and ":" in entry.unique_id
|
||||
and mac_matches_by_one(entry.unique_id, mac)
|
||||
for entry in self._async_current_entries(include_ignore=True):
|
||||
if not (
|
||||
entry.data.get(CONF_HOST) == device[ATTR_IPADDR]
|
||||
or (
|
||||
entry.unique_id
|
||||
and ":" in entry.unique_id
|
||||
and mac_matches_by_one(entry.unique_id, mac)
|
||||
)
|
||||
):
|
||||
if (
|
||||
async_update_entry_from_discovery(
|
||||
self.hass, entry, device, None, allow_update_mac
|
||||
)
|
||||
or entry.state == config_entries.ConfigEntryState.SETUP_RETRY
|
||||
):
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(entry.entry_id)
|
||||
)
|
||||
else:
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
FLUX_LED_DISCOVERY_SIGNAL.format(entry_id=entry.entry_id),
|
||||
)
|
||||
continue
|
||||
if entry.source == config_entries.SOURCE_IGNORE:
|
||||
raise AbortFlow("already_configured")
|
||||
if (
|
||||
async_update_entry_from_discovery(
|
||||
self.hass, entry, device, None, allow_update_mac
|
||||
)
|
||||
or entry.state == config_entries.ConfigEntryState.SETUP_RETRY
|
||||
):
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(entry.entry_id)
|
||||
)
|
||||
else:
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
FLUX_LED_DISCOVERY_SIGNAL.format(entry_id=entry.entry_id),
|
||||
)
|
||||
raise AbortFlow("already_configured")
|
||||
|
||||
async def _async_handle_discovery(self) -> FlowResult:
|
||||
"""Handle any discovery."""
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "frontend",
|
||||
"name": "Home Assistant Frontend",
|
||||
"documentation": "https://www.home-assistant.io/integrations/frontend",
|
||||
"requirements": ["home-assistant-frontend==20220728.0"],
|
||||
"requirements": ["home-assistant-frontend==20220802.0"],
|
||||
"dependencies": [
|
||||
"api",
|
||||
"auth",
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.bluetooth import BluetoothScanningMode
|
||||
from homeassistant.components.bluetooth.passive_update_processor import (
|
||||
PassiveBluetoothProcessorCoordinator,
|
||||
)
|
||||
@@ -27,6 +28,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass,
|
||||
_LOGGER,
|
||||
address=address,
|
||||
mode=BluetoothScanningMode.ACTIVE,
|
||||
)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(
|
||||
|
||||
@@ -7,7 +7,7 @@ from govee_ble import GoveeBluetoothDeviceData as DeviceData
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
BluetoothServiceInfo,
|
||||
BluetoothServiceInfoBleak,
|
||||
async_discovered_service_info,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigFlow
|
||||
@@ -24,12 +24,12 @@ class GoveeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the config flow."""
|
||||
self._discovery_info: BluetoothServiceInfo | None = None
|
||||
self._discovery_info: BluetoothServiceInfoBleak | None = None
|
||||
self._discovered_device: DeviceData | None = None
|
||||
self._discovered_devices: dict[str, str] = {}
|
||||
|
||||
async def async_step_bluetooth(
|
||||
self, discovery_info: BluetoothServiceInfo
|
||||
self, discovery_info: BluetoothServiceInfoBleak
|
||||
) -> FlowResult:
|
||||
"""Handle the bluetooth discovery step."""
|
||||
await self.async_set_unique_id(discovery_info.address)
|
||||
@@ -67,6 +67,7 @@ class GoveeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
address = user_input[CONF_ADDRESS]
|
||||
await self.async_set_unique_id(address, raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=self._discovered_devices[address], data={}
|
||||
)
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
"manufacturer_id": 18994,
|
||||
"service_uuid": "00008551-0000-1000-8000-00805f9b34fb"
|
||||
},
|
||||
{
|
||||
"manufacturer_id": 818,
|
||||
"service_uuid": "00008551-0000-1000-8000-00805f9b34fb"
|
||||
},
|
||||
{
|
||||
"manufacturer_id": 59970,
|
||||
"service_uuid": "00008151-0000-1000-8000-00805f9b34fb"
|
||||
},
|
||||
{
|
||||
"manufacturer_id": 14474,
|
||||
"service_uuid": "00008151-0000-1000-8000-00805f9b34fb"
|
||||
@@ -24,7 +32,7 @@
|
||||
"service_uuid": "00008251-0000-1000-8000-00805f9b34fb"
|
||||
}
|
||||
],
|
||||
"requirements": ["govee-ble==0.12.4"],
|
||||
"requirements": ["govee-ble==0.14.1"],
|
||||
"dependencies": ["bluetooth"],
|
||||
"codeowners": ["@bdraco"],
|
||||
"iot_class": "local_push"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from homeassistant.components.network import async_get_ipv4_broadcast_addresses
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -32,7 +33,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
async def _async_scan_update(_=None):
|
||||
await gree_discovery.discovery.scan()
|
||||
bcast_addr = list(await async_get_ipv4_broadcast_addresses(hass))
|
||||
await gree_discovery.discovery.scan(0, bcast_ifaces=bcast_addr)
|
||||
|
||||
_LOGGER.debug("Scanning network for Gree devices")
|
||||
await _async_scan_update()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Config flow for Gree."""
|
||||
from greeclimate.discovery import Discovery
|
||||
|
||||
from homeassistant.components.network import async_get_ipv4_broadcast_addresses
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_entry_flow
|
||||
|
||||
@@ -10,7 +11,10 @@ from .const import DISCOVERY_TIMEOUT, DOMAIN
|
||||
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
||||
"""Return if there are devices that can be discovered."""
|
||||
gree_discovery = Discovery(DISCOVERY_TIMEOUT)
|
||||
devices = await gree_discovery.scan(wait_for=DISCOVERY_TIMEOUT)
|
||||
bcast_addr = list(await async_get_ipv4_broadcast_addresses(hass))
|
||||
devices = await gree_discovery.scan(
|
||||
wait_for=DISCOVERY_TIMEOUT, bcast_ifaces=bcast_addr
|
||||
)
|
||||
return len(devices) > 0
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"name": "Gree Climate",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/gree",
|
||||
"requirements": ["greeclimate==1.2.0"],
|
||||
"requirements": ["greeclimate==1.3.0"],
|
||||
"dependencies": ["network"],
|
||||
"codeowners": ["@cmroche"],
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["greeclimate"]
|
||||
|
||||
@@ -137,6 +137,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
# so we use a lock to ensure that only one API request is reaching it at a time:
|
||||
api_lock = asyncio.Lock()
|
||||
|
||||
async def async_init_coordinator(
|
||||
coordinator: GuardianDataUpdateCoordinator,
|
||||
) -> None:
|
||||
"""Initialize a GuardianDataUpdateCoordinator."""
|
||||
await coordinator.async_initialize()
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
# Set up GuardianDataUpdateCoordinators for the valve controller:
|
||||
valve_controller_coordinators: dict[str, GuardianDataUpdateCoordinator] = {}
|
||||
init_valve_controller_tasks = []
|
||||
@@ -151,13 +158,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
api
|
||||
] = GuardianDataUpdateCoordinator(
|
||||
hass,
|
||||
entry=entry,
|
||||
client=client,
|
||||
api_name=api,
|
||||
api_coro=api_coro,
|
||||
api_lock=api_lock,
|
||||
valve_controller_uid=entry.data[CONF_UID],
|
||||
)
|
||||
init_valve_controller_tasks.append(coordinator.async_refresh())
|
||||
init_valve_controller_tasks.append(async_init_coordinator(coordinator))
|
||||
|
||||
await asyncio.gather(*init_valve_controller_tasks)
|
||||
|
||||
@@ -352,6 +360,7 @@ class PairedSensorManager:
|
||||
|
||||
coordinator = self.coordinators[uid] = GuardianDataUpdateCoordinator(
|
||||
self._hass,
|
||||
entry=self._entry,
|
||||
client=self._client,
|
||||
api_name=f"{API_SENSOR_PAIRED_SENSOR_STATUS}_{uid}",
|
||||
api_coro=lambda: cast(
|
||||
@@ -422,7 +431,7 @@ class GuardianEntity(CoordinatorEntity[GuardianDataUpdateCoordinator]):
|
||||
|
||||
@callback
|
||||
def _async_update_from_latest_data(self) -> None:
|
||||
"""Update the entity.
|
||||
"""Update the entity's underlying data.
|
||||
|
||||
This should be extended by Guardian platforms.
|
||||
"""
|
||||
|
||||
@@ -137,7 +137,7 @@ class PairedSensorBinarySensor(PairedSensorEntity, BinarySensorEntity):
|
||||
|
||||
@callback
|
||||
def _async_update_from_latest_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
"""Update the entity's underlying data."""
|
||||
if self.entity_description.key == SENSOR_KIND_LEAK_DETECTED:
|
||||
self._attr_is_on = self.coordinator.data["wet"]
|
||||
elif self.entity_description.key == SENSOR_KIND_MOVED:
|
||||
|
||||
@@ -15,6 +15,7 @@ from homeassistant.components.button import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
@@ -111,3 +112,5 @@ class GuardianButton(ValveControllerEntity, ButtonEntity):
|
||||
raise HomeAssistantError(
|
||||
f'Error while pressing button "{self.entity_id}": {err}'
|
||||
) from err
|
||||
|
||||
async_dispatcher_send(self.hass, self.coordinator.signal_reboot_requested)
|
||||
|
||||
@@ -128,7 +128,7 @@ class PairedSensorSensor(PairedSensorEntity, SensorEntity):
|
||||
|
||||
@callback
|
||||
def _async_update_from_latest_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
"""Update the entity's underlying data."""
|
||||
if self.entity_description.key == SENSOR_KIND_BATTERY:
|
||||
self._attr_native_value = self.coordinator.data["battery"]
|
||||
elif self.entity_description.key == SENSOR_KIND_TEMPERATURE:
|
||||
@@ -142,7 +142,7 @@ class ValveControllerSensor(ValveControllerEntity, SensorEntity):
|
||||
|
||||
@callback
|
||||
def _async_update_from_latest_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
"""Update the entity's underlying data."""
|
||||
if self.entity_description.key == SENSOR_KIND_TEMPERATURE:
|
||||
self._attr_native_value = self.coordinator.data["temperature"]
|
||||
elif self.entity_description.key == SENSOR_KIND_UPTIME:
|
||||
|
||||
@@ -9,21 +9,28 @@ from typing import Any, cast
|
||||
from aioguardian import Client
|
||||
from aioguardian.errors import GuardianError
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import LOGGER
|
||||
|
||||
DEFAULT_UPDATE_INTERVAL = timedelta(seconds=30)
|
||||
|
||||
SIGNAL_REBOOT_REQUESTED = "guardian_reboot_requested_{0}"
|
||||
|
||||
|
||||
class GuardianDataUpdateCoordinator(DataUpdateCoordinator[dict]):
|
||||
"""Define an extended DataUpdateCoordinator with some Guardian goodies."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
*,
|
||||
entry: ConfigEntry,
|
||||
client: Client,
|
||||
api_name: str,
|
||||
api_coro: Callable[..., Awaitable],
|
||||
@@ -41,6 +48,12 @@ class GuardianDataUpdateCoordinator(DataUpdateCoordinator[dict]):
|
||||
self._api_coro = api_coro
|
||||
self._api_lock = api_lock
|
||||
self._client = client
|
||||
self._signal_handler_unsubs: list[Callable[..., None]] = []
|
||||
|
||||
self.config_entry = entry
|
||||
self.signal_reboot_requested = SIGNAL_REBOOT_REQUESTED.format(
|
||||
self.config_entry.entry_id
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> dict[str, Any]:
|
||||
"""Execute a "locked" API request against the valve controller."""
|
||||
@@ -50,3 +63,26 @@ class GuardianDataUpdateCoordinator(DataUpdateCoordinator[dict]):
|
||||
except GuardianError as err:
|
||||
raise UpdateFailed(err) from err
|
||||
return cast(dict[str, Any], resp["data"])
|
||||
|
||||
async def async_initialize(self) -> None:
|
||||
"""Initialize the coordinator."""
|
||||
|
||||
@callback
|
||||
def async_reboot_requested() -> None:
|
||||
"""Respond to a reboot request."""
|
||||
self.last_update_success = False
|
||||
self.async_update_listeners()
|
||||
|
||||
self._signal_handler_unsubs.append(
|
||||
async_dispatcher_connect(
|
||||
self.hass, self.signal_reboot_requested, async_reboot_requested
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_teardown() -> None:
|
||||
"""Tear the coordinator down appropriately."""
|
||||
for unsub in self._signal_handler_unsubs:
|
||||
unsub()
|
||||
|
||||
self.config_entry.async_on_unload(async_teardown)
|
||||
|
||||
@@ -223,12 +223,24 @@ HARDWARE_INTEGRATIONS = {
|
||||
async def async_get_addon_info(hass: HomeAssistant, slug: str) -> dict:
|
||||
"""Return add-on info.
|
||||
|
||||
The add-on must be installed.
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio = hass.data[DOMAIN]
|
||||
return await hassio.get_addon_info(slug)
|
||||
|
||||
|
||||
@api_data
|
||||
async def async_get_addon_store_info(hass: HomeAssistant, slug: str) -> dict:
|
||||
"""Return add-on store info.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio: HassIO = hass.data[DOMAIN]
|
||||
command = f"/store/addons/{slug}"
|
||||
return await hassio.send_command(command, method="get")
|
||||
|
||||
|
||||
@bind_hass
|
||||
async def async_update_diagnostics(hass: HomeAssistant, diagnostics: bool) -> dict:
|
||||
"""Update Supervisor diagnostics toggle.
|
||||
|
||||
@@ -117,24 +117,22 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Home Connect component."""
|
||||
hass.data[DOMAIN] = {}
|
||||
|
||||
if DOMAIN not in config:
|
||||
return True
|
||||
|
||||
await async_import_client_credential(
|
||||
hass,
|
||||
DOMAIN,
|
||||
ClientCredential(
|
||||
config[DOMAIN][CONF_CLIENT_ID],
|
||||
config[DOMAIN][CONF_CLIENT_SECRET],
|
||||
),
|
||||
)
|
||||
_LOGGER.warning(
|
||||
"Configuration of Home Connect integration in YAML is deprecated and "
|
||||
"will be removed in a future release; Your existing OAuth "
|
||||
"Application Credentials have been imported into the UI "
|
||||
"automatically and can be safely removed from your "
|
||||
"configuration.yaml file"
|
||||
)
|
||||
if DOMAIN in config:
|
||||
await async_import_client_credential(
|
||||
hass,
|
||||
DOMAIN,
|
||||
ClientCredential(
|
||||
config[DOMAIN][CONF_CLIENT_ID],
|
||||
config[DOMAIN][CONF_CLIENT_SECRET],
|
||||
),
|
||||
)
|
||||
_LOGGER.warning(
|
||||
"Configuration of Home Connect integration in YAML is deprecated and "
|
||||
"will be removed in a future release; Your existing OAuth "
|
||||
"Application Credentials have been imported into the UI "
|
||||
"automatically and can be safely removed from your "
|
||||
"configuration.yaml file"
|
||||
)
|
||||
|
||||
async def _async_service_program(call, method):
|
||||
"""Execute calls to services taking a program."""
|
||||
|
||||
@@ -14,6 +14,7 @@ from homeassistant.components.repairs.models import IssueSeverity
|
||||
from homeassistant.const import __version__
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.start import async_at_start
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
from homeassistant.util.yaml import parse_yaml
|
||||
@@ -100,7 +101,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
coordinator = AlertUpdateCoordinator(hass)
|
||||
coordinator.async_add_listener(async_schedule_update_alerts)
|
||||
await coordinator.async_refresh()
|
||||
|
||||
async def initial_refresh(hass: HomeAssistant) -> None:
|
||||
await coordinator.async_refresh()
|
||||
|
||||
async_at_start(hass, initial_refresh)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"domain": "homeassistant_alerts",
|
||||
"name": "Home Assistant alerts",
|
||||
"name": "Home Assistant Alerts",
|
||||
"config_flow": false,
|
||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_alerts",
|
||||
"codeowners": ["@home-assistant/core"],
|
||||
|
||||
@@ -31,7 +31,7 @@ from homeassistant.helpers.typing import ConfigType
|
||||
from .config_flow import normalize_hkid
|
||||
from .connection import HKDevice, valid_serial_number
|
||||
from .const import ENTITY_MAP, KNOWN_DEVICES, TRIGGERS
|
||||
from .storage import async_get_entity_storage
|
||||
from .storage import EntityMapStorage, async_get_entity_storage
|
||||
from .utils import async_get_controller, folded_name
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -269,7 +269,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hkid = entry.data["AccessoryPairingID"]
|
||||
|
||||
if hkid in hass.data[KNOWN_DEVICES]:
|
||||
connection = hass.data[KNOWN_DEVICES][hkid]
|
||||
connection: HKDevice = hass.data[KNOWN_DEVICES][hkid]
|
||||
await connection.async_unload()
|
||||
|
||||
return True
|
||||
@@ -280,7 +280,8 @@ async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
hkid = entry.data["AccessoryPairingID"]
|
||||
|
||||
# Remove cached type data from .storage/homekit_controller-entity-map
|
||||
hass.data[ENTITY_MAP].async_delete_map(hkid)
|
||||
entity_map_storage: EntityMapStorage = hass.data[ENTITY_MAP]
|
||||
entity_map_storage.async_delete_map(hkid)
|
||||
|
||||
controller = await async_get_controller(hass)
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
"""Config flow to configure homekit_controller."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable
|
||||
import logging
|
||||
import re
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
import aiohomekit
|
||||
from aiohomekit import Controller, const as aiohomekit_const
|
||||
from aiohomekit.controller.abstract import AbstractDiscovery, AbstractPairing
|
||||
from aiohomekit.controller.abstract import (
|
||||
AbstractDiscovery,
|
||||
AbstractPairing,
|
||||
FinishPairing,
|
||||
)
|
||||
from aiohomekit.exceptions import AuthenticationError
|
||||
from aiohomekit.model.categories import Categories
|
||||
from aiohomekit.model.status_flags import StatusFlags
|
||||
@@ -17,16 +20,19 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import AbortFlow, FlowResult
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.service_info import bluetooth
|
||||
|
||||
from .connection import HKDevice
|
||||
from .const import DOMAIN, KNOWN_DEVICES
|
||||
from .storage import async_get_entity_storage
|
||||
from .utils import async_get_controller
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.components import bluetooth
|
||||
|
||||
|
||||
HOMEKIT_DIR = ".homekit"
|
||||
HOMEKIT_BRIDGE_DOMAIN = "homekit"
|
||||
|
||||
@@ -75,7 +81,9 @@ def formatted_category(category: Categories) -> str:
|
||||
|
||||
|
||||
@callback
|
||||
def find_existing_host(hass, serial: str) -> config_entries.ConfigEntry | None:
|
||||
def find_existing_host(
|
||||
hass: HomeAssistant, serial: str
|
||||
) -> config_entries.ConfigEntry | None:
|
||||
"""Return a set of the configured hosts."""
|
||||
for entry in hass.config_entries.async_entries(DOMAIN):
|
||||
if entry.data.get("AccessoryPairingID") == serial:
|
||||
@@ -112,15 +120,17 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self.category: Categories | None = None
|
||||
self.devices: dict[str, AbstractDiscovery] = {}
|
||||
self.controller: Controller | None = None
|
||||
self.finish_pairing: Awaitable[AbstractPairing] | None = None
|
||||
self.finish_pairing: FinishPairing | None = None
|
||||
|
||||
async def _async_setup_controller(self):
|
||||
async def _async_setup_controller(self) -> None:
|
||||
"""Create the controller."""
|
||||
self.controller = await async_get_controller(self.hass)
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle a flow start."""
|
||||
errors = {}
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input is not None:
|
||||
key = user_input["device"]
|
||||
@@ -139,6 +149,8 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
if self.controller is None:
|
||||
await self._async_setup_controller()
|
||||
|
||||
assert self.controller
|
||||
|
||||
self.devices = {}
|
||||
|
||||
async for discovery in self.controller.async_discover():
|
||||
@@ -164,7 +176,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
),
|
||||
)
|
||||
|
||||
async def async_step_unignore(self, user_input):
|
||||
async def async_step_unignore(self, user_input: dict[str, Any]) -> FlowResult:
|
||||
"""Rediscover a previously ignored discover."""
|
||||
unique_id = user_input["unique_id"]
|
||||
await self.async_set_unique_id(unique_id)
|
||||
@@ -172,19 +184,21 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
if self.controller is None:
|
||||
await self._async_setup_controller()
|
||||
|
||||
assert self.controller
|
||||
|
||||
try:
|
||||
discovery = await self.controller.async_find(unique_id)
|
||||
except aiohomekit.AccessoryNotFoundError:
|
||||
return self.async_abort(reason="accessory_not_found_error")
|
||||
|
||||
self.name = discovery.description.name
|
||||
self.model = discovery.description.model
|
||||
self.model = getattr(discovery.description, "model", BLE_DEFAULT_NAME)
|
||||
self.category = discovery.description.category
|
||||
self.hkid = discovery.description.id
|
||||
|
||||
return self._async_step_pair_show_form()
|
||||
|
||||
async def _hkid_is_homekit(self, hkid):
|
||||
async def _hkid_is_homekit(self, hkid: str) -> bool:
|
||||
"""Determine if the device is a homekit bridge or accessory."""
|
||||
dev_reg = dr.async_get(self.hass)
|
||||
device = dev_reg.async_get_device(
|
||||
@@ -359,7 +373,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return self._async_step_pair_show_form()
|
||||
|
||||
async def async_step_bluetooth(
|
||||
self, discovery_info: bluetooth.BluetoothServiceInfo
|
||||
self, discovery_info: bluetooth.BluetoothServiceInfoBleak
|
||||
) -> FlowResult:
|
||||
"""Handle the bluetooth discovery step."""
|
||||
if not aiohomekit_const.BLE_TRANSPORT_SUPPORTED:
|
||||
@@ -407,7 +421,9 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
return self._async_step_pair_show_form()
|
||||
|
||||
async def async_step_pair(self, pair_info=None):
|
||||
async def async_step_pair(
|
||||
self, pair_info: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Pair with a new HomeKit accessory."""
|
||||
# If async_step_pair is called with no pairing code then we do the M1
|
||||
# phase of pairing. If this is successful the device enters pairing
|
||||
@@ -425,11 +441,16 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
# callable. We call the callable with the pin that the user has typed
|
||||
# in.
|
||||
|
||||
# Should never call this step without setting self.hkid
|
||||
assert self.hkid
|
||||
|
||||
errors = {}
|
||||
|
||||
if self.controller is None:
|
||||
await self._async_setup_controller()
|
||||
|
||||
assert self.controller
|
||||
|
||||
if pair_info and self.finish_pairing:
|
||||
self.context["pairing"] = True
|
||||
code = pair_info["pairing_code"]
|
||||
@@ -504,21 +525,27 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
return self._async_step_pair_show_form(errors)
|
||||
|
||||
async def async_step_busy_error(self, user_input=None):
|
||||
async def async_step_busy_error(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Retry pairing after the accessory is busy."""
|
||||
if user_input is not None:
|
||||
return await self.async_step_pair()
|
||||
|
||||
return self.async_show_form(step_id="busy_error")
|
||||
|
||||
async def async_step_max_tries_error(self, user_input=None):
|
||||
async def async_step_max_tries_error(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Retry pairing after the accessory has reached max tries."""
|
||||
if user_input is not None:
|
||||
return await self.async_step_pair()
|
||||
|
||||
return self.async_show_form(step_id="max_tries_error")
|
||||
|
||||
async def async_step_protocol_error(self, user_input=None):
|
||||
async def async_step_protocol_error(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Retry pairing after the accessory has a protocol error."""
|
||||
if user_input is not None:
|
||||
return await self.async_step_pair()
|
||||
@@ -526,7 +553,11 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return self.async_show_form(step_id="protocol_error")
|
||||
|
||||
@callback
|
||||
def _async_step_pair_show_form(self, errors=None):
|
||||
def _async_step_pair_show_form(
|
||||
self, errors: dict[str, str] | None = None
|
||||
) -> FlowResult:
|
||||
assert self.category
|
||||
|
||||
placeholders = self.context["title_placeholders"] = {
|
||||
"name": self.name,
|
||||
"category": formatted_category(self.category),
|
||||
@@ -566,7 +597,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
entity_storage = await async_get_entity_storage(self.hass)
|
||||
assert self.unique_id is not None
|
||||
entity_storage.async_create_or_update_map(
|
||||
self.unique_id,
|
||||
pairing.id,
|
||||
accessories_state.config_num,
|
||||
accessories_state.accessories.serialize(),
|
||||
)
|
||||
|
||||
@@ -107,9 +107,9 @@ class HomeKitLight(HomeKitEntity, LightEntity):
|
||||
return ColorMode.ONOFF
|
||||
|
||||
@property
|
||||
def supported_color_modes(self) -> set[ColorMode | str] | None:
|
||||
def supported_color_modes(self) -> set[ColorMode]:
|
||||
"""Flag supported color modes."""
|
||||
color_modes: set[ColorMode | str] = set()
|
||||
color_modes: set[ColorMode] = set()
|
||||
|
||||
if self.service.has(CharacteristicsTypes.HUE) or self.service.has(
|
||||
CharacteristicsTypes.SATURATION
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "HomeKit Controller",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/homekit_controller",
|
||||
"requirements": ["aiohomekit==1.2.2"],
|
||||
"requirements": ["aiohomekit==1.2.9"],
|
||||
"zeroconf": ["_hap._tcp.local.", "_hap._udp.local."],
|
||||
"bluetooth": [{ "manufacturer_id": 76, "manufacturer_data_start": [6] }],
|
||||
"dependencies": ["bluetooth", "zeroconf"],
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, TypedDict
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
@@ -12,6 +13,7 @@ from .const import DOMAIN, ENTITY_MAP
|
||||
ENTITY_MAP_STORAGE_KEY = f"{DOMAIN}-entity-map"
|
||||
ENTITY_MAP_STORAGE_VERSION = 1
|
||||
ENTITY_MAP_SAVE_DELAY = 10
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Pairing(TypedDict):
|
||||
@@ -68,6 +70,7 @@ class EntityMapStorage:
|
||||
self, homekit_id: str, config_num: int, accessories: list[Any]
|
||||
) -> Pairing:
|
||||
"""Create a new pairing cache."""
|
||||
_LOGGER.debug("Creating or updating entity map for %s", homekit_id)
|
||||
data = Pairing(config_num=config_num, accessories=accessories)
|
||||
self.storage_data[homekit_id] = data
|
||||
self._async_schedule_save()
|
||||
@@ -76,11 +79,17 @@ class EntityMapStorage:
|
||||
@callback
|
||||
def async_delete_map(self, homekit_id: str) -> None:
|
||||
"""Delete pairing cache."""
|
||||
if homekit_id not in self.storage_data:
|
||||
return
|
||||
|
||||
self.storage_data.pop(homekit_id)
|
||||
self._async_schedule_save()
|
||||
removed_one = False
|
||||
# Previously there was a bug where a lowercase homekit_id was stored
|
||||
# in the storage. We need to account for that.
|
||||
for hkid in (homekit_id, homekit_id.lower()):
|
||||
if hkid not in self.storage_data:
|
||||
continue
|
||||
_LOGGER.debug("Deleting entity map for %s", hkid)
|
||||
self.storage_data.pop(hkid)
|
||||
removed_one = True
|
||||
if removed_one:
|
||||
self._async_schedule_save()
|
||||
|
||||
@callback
|
||||
def _async_schedule_save(self) -> None:
|
||||
|
||||
@@ -32,7 +32,7 @@ async def async_get_controller(hass: HomeAssistant) -> Controller:
|
||||
|
||||
controller = Controller(
|
||||
async_zeroconf_instance=async_zeroconf_instance,
|
||||
bleak_scanner_instance=bleak_scanner_instance,
|
||||
bleak_scanner_instance=bleak_scanner_instance, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
hass.data[CONTROLLER] = controller
|
||||
|
||||
@@ -279,11 +279,12 @@ class Router:
|
||||
self._get_data(
|
||||
KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH,
|
||||
lambda: next(
|
||||
filter(
|
||||
lambda ssid: ssid.get("wifiisguestnetwork") == "1",
|
||||
self.client.wlan.multi_basic_settings()
|
||||
(
|
||||
ssid
|
||||
for ssid in self.client.wlan.multi_basic_settings()
|
||||
.get("Ssids", {})
|
||||
.get("Ssid", []),
|
||||
.get("Ssid", [])
|
||||
if isinstance(ssid, dict) and ssid.get("wifiisguestnetwork") == "1"
|
||||
),
|
||||
{},
|
||||
),
|
||||
|
||||
@@ -37,7 +37,7 @@ async def async_setup_entry(
|
||||
if router.data.get(KEY_DIALUP_MOBILE_DATASWITCH):
|
||||
switches.append(HuaweiLteMobileDataSwitch(router))
|
||||
|
||||
if router.data.get(KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH).get("WifiEnable"):
|
||||
if router.data.get(KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH, {}).get("WifiEnable"):
|
||||
switches.append(HuaweiLteWifiGuestNetworkSwitch(router))
|
||||
|
||||
async_add_entities(switches, True)
|
||||
@@ -151,6 +151,6 @@ class HuaweiLteWifiGuestNetworkSwitch(HuaweiLteBaseSwitch):
|
||||
return "mdi:wifi" if self.is_on else "mdi:wifi-off"
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, str]:
|
||||
def extra_state_attributes(self) -> dict[str, str | None]:
|
||||
"""Return the state attributes."""
|
||||
return {"ssid": self.router.data[self.key].get("WifiSsid")}
|
||||
|
||||
@@ -17,7 +17,7 @@ from pyicloud.services.findmyiphone import AppleDevice
|
||||
from homeassistant.components.zone import async_active_zone
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
from homeassistant.helpers.event import track_point_in_utc_time
|
||||
@@ -104,6 +104,8 @@ class IcloudAccount:
|
||||
self._retried_fetch = False
|
||||
self._config_entry = config_entry
|
||||
|
||||
self.listeners: list[CALLBACK_TYPE] = []
|
||||
|
||||
def setup(self) -> None:
|
||||
"""Set up an iCloud account."""
|
||||
try:
|
||||
|
||||
@@ -35,7 +35,7 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up device tracker for iCloud component."""
|
||||
account = hass.data[DOMAIN][entry.unique_id]
|
||||
account: IcloudAccount = hass.data[DOMAIN][entry.unique_id]
|
||||
tracked = set[str]()
|
||||
|
||||
@callback
|
||||
|
||||
@@ -20,7 +20,7 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up device tracker for iCloud component."""
|
||||
account = hass.data[DOMAIN][entry.unique_id]
|
||||
account: IcloudAccount = hass.data[DOMAIN][entry.unique_id]
|
||||
tracked = set[str]()
|
||||
|
||||
@callback
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.bluetooth import BluetoothScanningMode
|
||||
from homeassistant.components.bluetooth.passive_update_processor import (
|
||||
PassiveBluetoothProcessorCoordinator,
|
||||
)
|
||||
@@ -24,9 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
coordinator = hass.data.setdefault(DOMAIN, {})[
|
||||
entry.entry_id
|
||||
] = PassiveBluetoothProcessorCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
address=address,
|
||||
hass, _LOGGER, address=address, mode=BluetoothScanningMode.ACTIVE
|
||||
)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(
|
||||
|
||||
@@ -7,7 +7,7 @@ from inkbird_ble import INKBIRDBluetoothDeviceData as DeviceData
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
BluetoothServiceInfo,
|
||||
BluetoothServiceInfoBleak,
|
||||
async_discovered_service_info,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigFlow
|
||||
@@ -24,12 +24,12 @@ class INKBIRDConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the config flow."""
|
||||
self._discovery_info: BluetoothServiceInfo | None = None
|
||||
self._discovery_info: BluetoothServiceInfoBleak | None = None
|
||||
self._discovered_device: DeviceData | None = None
|
||||
self._discovered_devices: dict[str, str] = {}
|
||||
|
||||
async def async_step_bluetooth(
|
||||
self, discovery_info: BluetoothServiceInfo
|
||||
self, discovery_info: BluetoothServiceInfoBleak
|
||||
) -> FlowResult:
|
||||
"""Handle the bluetooth discovery step."""
|
||||
await self.async_set_unique_id(discovery_info.address)
|
||||
@@ -67,6 +67,7 @@ class INKBIRDConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
address = user_input[CONF_ADDRESS]
|
||||
await self.async_set_unique_id(address, raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=self._discovered_devices[address], data={}
|
||||
)
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
{ "local_name": "sps" },
|
||||
{ "local_name": "Inkbird*" },
|
||||
{ "local_name": "iBBQ*" },
|
||||
{ "local_name": "xBBQ*" },
|
||||
{ "local_name": "tps" }
|
||||
],
|
||||
"requirements": ["inkbird-ble==0.5.1"],
|
||||
"requirements": ["inkbird-ble==0.5.2"],
|
||||
"dependencies": ["bluetooth"],
|
||||
"codeowners": ["@bdraco"],
|
||||
"iot_class": "local_push"
|
||||
|
||||
@@ -223,6 +223,7 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
||||
== SensorDeviceClass.POWER
|
||||
):
|
||||
self._attr_device_class = SensorDeviceClass.ENERGY
|
||||
self._attr_icon = None
|
||||
update_state = True
|
||||
|
||||
if update_state:
|
||||
|
||||
@@ -363,14 +363,18 @@ class JellyfinSource(MediaSource):
|
||||
|
||||
def _media_mime_type(media_item: dict[str, Any]) -> str:
|
||||
"""Return the mime type of a media item."""
|
||||
if not media_item[ITEM_KEY_MEDIA_SOURCES]:
|
||||
if not media_item.get(ITEM_KEY_MEDIA_SOURCES):
|
||||
raise BrowseError("Unable to determine mime type for item without media source")
|
||||
|
||||
media_source = media_item[ITEM_KEY_MEDIA_SOURCES][0]
|
||||
|
||||
if MEDIA_SOURCE_KEY_PATH not in media_source:
|
||||
raise BrowseError("Unable to determine mime type for media source without path")
|
||||
|
||||
path = media_source[MEDIA_SOURCE_KEY_PATH]
|
||||
mime_type, _ = mimetypes.guess_type(path)
|
||||
|
||||
if mime_type is not None:
|
||||
return mime_type
|
||||
if mime_type is None:
|
||||
raise BrowseError(f"Unable to determine mime type for path {path}")
|
||||
|
||||
raise BrowseError(f"Unable to determine mime type for path {path}")
|
||||
return mime_type
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "KNX",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/knx",
|
||||
"requirements": ["xknx==0.22.0"],
|
||||
"requirements": ["xknx==0.22.1"],
|
||||
"codeowners": ["@Julius2342", "@farmio", "@marvin-w"],
|
||||
"quality_scale": "platinum",
|
||||
"iot_class": "local_push",
|
||||
|
||||
@@ -47,7 +47,6 @@ class LGDevice(MediaPlayerEntity):
|
||||
self._port = port
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
self._name = None
|
||||
self._volume = 0
|
||||
self._volume_min = 0
|
||||
self._volume_max = 0
|
||||
@@ -94,8 +93,6 @@ class LGDevice(MediaPlayerEntity):
|
||||
elif response["msg"] == "SPK_LIST_VIEW_INFO":
|
||||
if "i_vol" in data:
|
||||
self._volume = data["i_vol"]
|
||||
if "s_user_name" in data:
|
||||
self._name = data["s_user_name"]
|
||||
if "i_vol_min" in data:
|
||||
self._volume_min = data["i_vol_min"]
|
||||
if "i_vol_max" in data:
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
},
|
||||
"abort": {
|
||||
"existing_instance_updated": "Updated existing configuration.",
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "Service is already configured",
|
||||
"existing_instance_updated": "Updated existing configuration."
|
||||
"already_configured": "Device is already configured"
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "Failed to connect"
|
||||
|
||||
@@ -91,9 +91,11 @@ class Life360Data:
|
||||
members: dict[str, Life360Member] = field(init=False, default_factory=dict)
|
||||
|
||||
|
||||
class Life360DataUpdateCoordinator(DataUpdateCoordinator):
|
||||
class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
|
||||
"""Life360 data update coordinator."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
|
||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Initialize data update coordinator."""
|
||||
super().__init__(
|
||||
|
||||
@@ -11,10 +11,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_BATTERY_CHARGING
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
ATTR_ADDRESS,
|
||||
@@ -31,6 +28,7 @@ from .const import (
|
||||
LOGGER,
|
||||
SHOW_DRIVING,
|
||||
)
|
||||
from .coordinator import Life360DataUpdateCoordinator, Life360Member
|
||||
|
||||
_LOC_ATTRS = (
|
||||
"address",
|
||||
@@ -95,23 +93,27 @@ async def async_setup_entry(
|
||||
entry.async_on_unload(coordinator.async_add_listener(process_data))
|
||||
|
||||
|
||||
class Life360DeviceTracker(CoordinatorEntity, TrackerEntity):
|
||||
class Life360DeviceTracker(
|
||||
CoordinatorEntity[Life360DataUpdateCoordinator], TrackerEntity
|
||||
):
|
||||
"""Life360 Device Tracker."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_unique_id: str
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, member_id: str) -> None:
|
||||
def __init__(
|
||||
self, coordinator: Life360DataUpdateCoordinator, member_id: str
|
||||
) -> None:
|
||||
"""Initialize Life360 Entity."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = member_id
|
||||
|
||||
self._data = coordinator.data.members[self.unique_id]
|
||||
self._data: Life360Member | None = coordinator.data.members[member_id]
|
||||
self._prev_data = self._data
|
||||
|
||||
self._attr_name = self._data.name
|
||||
self._attr_entity_picture = self._data.entity_picture
|
||||
|
||||
self._prev_data = self._data
|
||||
|
||||
@property
|
||||
def _options(self) -> Mapping[str, Any]:
|
||||
"""Shortcut to config entry options."""
|
||||
@@ -120,16 +122,15 @@ class Life360DeviceTracker(CoordinatorEntity, TrackerEntity):
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
# Get a shortcut to this member's data. Can't guarantee it's the same dict every
|
||||
# update, or that there is even data for this member every update, so need to
|
||||
# update shortcut each time.
|
||||
self._data = self.coordinator.data.members.get(self.unique_id)
|
||||
|
||||
# Get a shortcut to this Member's data. This needs to be updated each time since
|
||||
# coordinator provides a new Life360Member object each time, and it's possible
|
||||
# that there is no data for this Member on some updates.
|
||||
if self.available:
|
||||
# If nothing important has changed, then skip the update altogether.
|
||||
if self._data == self._prev_data:
|
||||
return
|
||||
self._data = self.coordinator.data.members.get(self._attr_unique_id)
|
||||
else:
|
||||
self._data = None
|
||||
|
||||
if self._data:
|
||||
# Check if we should effectively throw out new location data.
|
||||
last_seen = self._data.last_seen
|
||||
prev_seen = self._prev_data.last_seen
|
||||
@@ -168,27 +169,21 @@ class Life360DeviceTracker(CoordinatorEntity, TrackerEntity):
|
||||
"""Return True if state updates should be forced."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return if entity is available."""
|
||||
# Guard against member not being in last update for some reason.
|
||||
return super().available and self._data is not None
|
||||
|
||||
@property
|
||||
def entity_picture(self) -> str | None:
|
||||
"""Return the entity picture to use in the frontend, if any."""
|
||||
if self.available:
|
||||
if self._data:
|
||||
self._attr_entity_picture = self._data.entity_picture
|
||||
return super().entity_picture
|
||||
|
||||
# All of the following will only be called if self.available is True.
|
||||
|
||||
@property
|
||||
def battery_level(self) -> int | None:
|
||||
"""Return the battery level of the device.
|
||||
|
||||
Percentage from 0-100.
|
||||
"""
|
||||
if not self._data:
|
||||
return None
|
||||
return self._data.battery_level
|
||||
|
||||
@property
|
||||
@@ -202,11 +197,15 @@ class Life360DeviceTracker(CoordinatorEntity, TrackerEntity):
|
||||
|
||||
Value in meters.
|
||||
"""
|
||||
if not self._data:
|
||||
return 0
|
||||
return self._data.gps_accuracy
|
||||
|
||||
@property
|
||||
def driving(self) -> bool:
|
||||
"""Return if driving."""
|
||||
if not self._data:
|
||||
return False
|
||||
if (driving_speed := self._options.get(CONF_DRIVING_SPEED)) is not None:
|
||||
if self._data.speed >= driving_speed:
|
||||
return True
|
||||
@@ -222,23 +221,38 @@ class Life360DeviceTracker(CoordinatorEntity, TrackerEntity):
|
||||
@property
|
||||
def latitude(self) -> float | None:
|
||||
"""Return latitude value of the device."""
|
||||
if not self._data:
|
||||
return None
|
||||
return self._data.latitude
|
||||
|
||||
@property
|
||||
def longitude(self) -> float | None:
|
||||
"""Return longitude value of the device."""
|
||||
if not self._data:
|
||||
return None
|
||||
return self._data.longitude
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
||||
"""Return entity specific state attributes."""
|
||||
attrs = {}
|
||||
attrs[ATTR_ADDRESS] = self._data.address
|
||||
attrs[ATTR_AT_LOC_SINCE] = self._data.at_loc_since
|
||||
attrs[ATTR_BATTERY_CHARGING] = self._data.battery_charging
|
||||
attrs[ATTR_DRIVING] = self.driving
|
||||
attrs[ATTR_LAST_SEEN] = self._data.last_seen
|
||||
attrs[ATTR_PLACE] = self._data.place
|
||||
attrs[ATTR_SPEED] = self._data.speed
|
||||
attrs[ATTR_WIFI_ON] = self._data.wifi_on
|
||||
return attrs
|
||||
if not self._data:
|
||||
return {
|
||||
ATTR_ADDRESS: None,
|
||||
ATTR_AT_LOC_SINCE: None,
|
||||
ATTR_BATTERY_CHARGING: None,
|
||||
ATTR_DRIVING: None,
|
||||
ATTR_LAST_SEEN: None,
|
||||
ATTR_PLACE: None,
|
||||
ATTR_SPEED: None,
|
||||
ATTR_WIFI_ON: None,
|
||||
}
|
||||
return {
|
||||
ATTR_ADDRESS: self._data.address,
|
||||
ATTR_AT_LOC_SINCE: self._data.at_loc_since,
|
||||
ATTR_BATTERY_CHARGING: self._data.battery_charging,
|
||||
ATTR_DRIVING: self.driving,
|
||||
ATTR_LAST_SEEN: self._data.last_seen,
|
||||
ATTR_PLACE: self._data.place,
|
||||
ATTR_SPEED: self._data.speed,
|
||||
ATTR_WIFI_ON: self._data.wifi_on,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"domain": "luci",
|
||||
"name": "OpenWRT (luci)",
|
||||
"name": "OpenWrt (luci)",
|
||||
"documentation": "https://www.home-assistant.io/integrations/luci",
|
||||
"requirements": ["openwrt-luci-rpc==1.1.11"],
|
||||
"codeowners": ["@mzdrale"],
|
||||
|
||||
@@ -43,14 +43,18 @@ class MeaterSensorEntityDescription(
|
||||
|
||||
def _elapsed_time_to_timestamp(probe: MeaterProbe) -> datetime | None:
|
||||
"""Convert elapsed time to timestamp."""
|
||||
if not probe.cook:
|
||||
if not probe.cook or not hasattr(probe.cook, "time_elapsed"):
|
||||
return None
|
||||
return dt_util.utcnow() - timedelta(seconds=probe.cook.time_elapsed)
|
||||
|
||||
|
||||
def _remaining_time_to_timestamp(probe: MeaterProbe) -> datetime | None:
|
||||
"""Convert remaining time to timestamp."""
|
||||
if not probe.cook or probe.cook.time_remaining < 0:
|
||||
if (
|
||||
not probe.cook
|
||||
or not hasattr(probe.cook, "time_remaining")
|
||||
or probe.cook.time_remaining < 0
|
||||
):
|
||||
return None
|
||||
return dt_util.utcnow() + timedelta(seconds=probe.cook.time_remaining)
|
||||
|
||||
@@ -99,7 +103,9 @@ SENSOR_TYPES = (
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
available=lambda probe: probe is not None and probe.cook is not None,
|
||||
value=lambda probe: probe.cook.target_temperature if probe.cook else None,
|
||||
value=lambda probe: probe.cook.target_temperature
|
||||
if probe.cook and hasattr(probe.cook, "target_temperature")
|
||||
else None,
|
||||
),
|
||||
# Peak temperature
|
||||
MeaterSensorEntityDescription(
|
||||
@@ -109,7 +115,9 @@ SENSOR_TYPES = (
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
available=lambda probe: probe is not None and probe.cook is not None,
|
||||
value=lambda probe: probe.cook.peak_temperature if probe.cook else None,
|
||||
value=lambda probe: probe.cook.peak_temperature
|
||||
if probe.cook and hasattr(probe.cook, "peak_temperature")
|
||||
else None,
|
||||
),
|
||||
# Remaining time in seconds. When unknown/calculating default is used. Default: -1
|
||||
# Exposed as a TIMESTAMP sensor where the timestamp is current time + remaining time.
|
||||
|
||||
@@ -116,7 +116,7 @@ class MikrotikDataUpdateCoordinatorTracker(
|
||||
return self.device.mac
|
||||
|
||||
@property
|
||||
def ip_address(self) -> str:
|
||||
def ip_address(self) -> str | None:
|
||||
"""Return the mac address of the client."""
|
||||
return self.device.ip_address
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ class Device:
|
||||
return self._params.get("host-name", self.mac)
|
||||
|
||||
@property
|
||||
def ip_address(self) -> str:
|
||||
def ip_address(self) -> str | None:
|
||||
"""Return device primary ip address."""
|
||||
return self._params["address"]
|
||||
return self._params.get("address")
|
||||
|
||||
@property
|
||||
def mac(self) -> str:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"issues": {
|
||||
"replaced": {
|
||||
"title": "The Xiaomi Mijia BLE Temperature and Humidity Sensor integration has been replaced",
|
||||
"description": "The Xiaomi Mijia BLE Temperature and Humidity Sensor integration stopped working in Home Assistant 2022.7 and was replaced by the Xiaomi BLE integration in the 2022.8 release.\n\nThere is no migration path possible, therefore, you have to add your Xiaomi Mijia BLE device using the new integration manually.\n\nYour existing Xiaomi Mijia BLE Temperature and Humidity sensor YAML configuration is no longer used by Home Assistant. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
"description": "The Xiaomi Mijia BLE Temperature and Humidity Sensor integration stopped working in Home Assistant 2022.7 and was replaced by the Xiaomi BLE integration in the 2022.8 release.\n\nThere is no migration path possible, therefore, you have to add your Xiaomi Mijia BLE device using the new integration manually.\n\nYour existing Xiaomi Mijia BLE Temperature and Humidity Sensor YAML configuration is no longer used by Home Assistant. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"issues": {
|
||||
"replaced": {
|
||||
"description": "The Xiaomi Mijia BLE Temperature and Humidity Sensor integration stopped working in Home Assistant 2022.7 and was replaced by the Xiaomi BLE integration in the 2022.8 release.\n\nThere is no migration path possible, therefore, you have to add your Xiaomi Mijia BLE device using the new integration manually.\n\nYour existing Xiaomi Mijia BLE Temperature and Humidity sensor YAML configuration is no longer used by Home Assistant. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
|
||||
"description": "The Xiaomi Mijia BLE Temperature and Humidity Sensor integration stopped working in Home Assistant 2022.7 and was replaced by the Xiaomi BLE integration in the 2022.8 release.\n\nThere is no migration path possible, therefore, you have to add your Xiaomi Mijia BLE device using the new integration manually.\n\nYour existing Xiaomi Mijia BLE Temperature and Humidity Sensor YAML configuration is no longer used by Home Assistant. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
|
||||
"title": "The Xiaomi Mijia BLE Temperature and Humidity Sensor integration has been replaced"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.bluetooth import BluetoothScanningMode
|
||||
from homeassistant.components.bluetooth.passive_update_processor import (
|
||||
PassiveBluetoothProcessorCoordinator,
|
||||
)
|
||||
@@ -24,9 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
coordinator = hass.data.setdefault(DOMAIN, {})[
|
||||
entry.entry_id
|
||||
] = PassiveBluetoothProcessorCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
address=address,
|
||||
hass, _LOGGER, address=address, mode=BluetoothScanningMode.PASSIVE
|
||||
)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(
|
||||
|
||||
@@ -7,7 +7,7 @@ from moat_ble import MoatBluetoothDeviceData as DeviceData
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
BluetoothServiceInfo,
|
||||
BluetoothServiceInfoBleak,
|
||||
async_discovered_service_info,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigFlow
|
||||
@@ -24,12 +24,12 @@ class MoatConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the config flow."""
|
||||
self._discovery_info: BluetoothServiceInfo | None = None
|
||||
self._discovery_info: BluetoothServiceInfoBleak | None = None
|
||||
self._discovered_device: DeviceData | None = None
|
||||
self._discovered_devices: dict[str, str] = {}
|
||||
|
||||
async def async_step_bluetooth(
|
||||
self, discovery_info: BluetoothServiceInfo
|
||||
self, discovery_info: BluetoothServiceInfoBleak
|
||||
) -> FlowResult:
|
||||
"""Handle the bluetooth discovery step."""
|
||||
await self.async_set_unique_id(discovery_info.address)
|
||||
@@ -67,6 +67,7 @@ class MoatConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
address = user_input[CONF_ADDRESS]
|
||||
await self.async_set_unique_id(address, raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=self._discovered_devices[address], data={}
|
||||
)
|
||||
|
||||
@@ -29,6 +29,11 @@ from homeassistant.components.application_credentials import (
|
||||
from homeassistant.components.camera import Image, img_util
|
||||
from homeassistant.components.http.const import KEY_HASS_USER
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.components.repairs import (
|
||||
IssueSeverity,
|
||||
async_create_issue,
|
||||
async_delete_issue,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_BINARY_SENSORS,
|
||||
@@ -187,6 +192,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
entry, unique_id=entry.data[CONF_PROJECT_ID]
|
||||
)
|
||||
|
||||
async_delete_issue(hass, DOMAIN, "removed_app_auth")
|
||||
|
||||
subscriber = await api.new_subscriber(hass, entry)
|
||||
if not subscriber:
|
||||
return False
|
||||
@@ -255,6 +262,18 @@ async def async_import_config(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
if entry.data["auth_implementation"] == INSTALLED_AUTH_DOMAIN:
|
||||
# App Auth credentials have been deprecated and must be re-created
|
||||
# by the user in the config flow
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"removed_app_auth",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.ERROR,
|
||||
translation_key="removed_app_auth",
|
||||
translation_placeholders={
|
||||
"more_info_url": "https://www.home-assistant.io/more-info/nest-auth-deprecation",
|
||||
"documentation_url": "https://www.home-assistant.io/integrations/nest/",
|
||||
},
|
||||
)
|
||||
raise ConfigEntryAuthFailed(
|
||||
"Google has deprecated App Auth credentials, and the integration "
|
||||
"must be reconfigured in the UI to restore access to Nest Devices."
|
||||
@@ -271,12 +290,14 @@ async def async_import_config(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
WEB_AUTH_DOMAIN,
|
||||
)
|
||||
|
||||
_LOGGER.warning(
|
||||
"Configuration of Nest integration in YAML is deprecated and "
|
||||
"will be removed in a future release; Your existing configuration "
|
||||
"(including OAuth Application Credentials) has been imported into "
|
||||
"the UI automatically and can be safely removed from your "
|
||||
"configuration.yaml file"
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"deprecated_yaml",
|
||||
breaks_in_ha_version="2022.10.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "nest",
|
||||
"name": "Nest",
|
||||
"config_flow": true,
|
||||
"dependencies": ["ffmpeg", "http", "application_credentials"],
|
||||
"dependencies": ["ffmpeg", "http", "application_credentials", "repairs"],
|
||||
"after_dependencies": ["media_source"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/nest",
|
||||
"requirements": ["python-nest==4.2.0", "google-nest-sdm==2.0.0"],
|
||||
|
||||
@@ -88,5 +88,15 @@
|
||||
"camera_sound": "Sound detected",
|
||||
"doorbell_chime": "Doorbell pressed"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml": {
|
||||
"title": "The Nest YAML configuration is being removed",
|
||||
"description": "Configuring Nest in configuration.yaml is being removed in Home Assistant 2022.10.\n\nYour existing OAuth Application Credentials and access settings have been imported into the UI automatically. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
},
|
||||
"removed_app_auth": {
|
||||
"title": "Nest Authentication Credentials must be updated",
|
||||
"description": "To improve security and reduce phishing risk Google has deprecated the authentication method used by Home Assistant.\n\n**This requires action by you to resolve** ([more info]({more_info_url}))\n\n1. Visit the integrations page\n1. Click Reconfigure on the Nest integration.\n1. Home Assistant will walk you through the steps to upgrade to Web Authentication.\n\nSee the Nest [integration instructions]({documentation_url}) for troubleshooting information."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
"missing_configuration": "The component is not configured. Please follow the documentation.",
|
||||
"no_url_available": "No URL available. For information about this error, [check the help section]({docs_url})",
|
||||
"reauth_successful": "Re-authentication was successful",
|
||||
"single_instance_allowed": "Already configured. Only a single configuration possible.",
|
||||
"unknown_authorize_url_generation": "Unknown error generating an authorize URL."
|
||||
},
|
||||
"create_entry": {
|
||||
@@ -26,13 +25,6 @@
|
||||
"wrong_project_id": "Please enter a valid Cloud Project ID (was same as Device Access Project ID)"
|
||||
},
|
||||
"step": {
|
||||
"auth": {
|
||||
"data": {
|
||||
"code": "Access Token"
|
||||
},
|
||||
"description": "To link your Google account, [authorize your account]({url}).\n\nAfter authorization, copy-paste the provided Auth Token code below.",
|
||||
"title": "Link Google Account"
|
||||
},
|
||||
"auth_upgrade": {
|
||||
"description": "App Auth has been deprecated by Google to improve security, and you need to take action by creating new application credentials.\n\nOpen the [documentation]({more_info_url}) to follow along as the next steps will guide you through the steps you need to take to restore access to your Nest devices.",
|
||||
"title": "Nest: App Auth Deprecation"
|
||||
@@ -96,5 +88,15 @@
|
||||
"camera_sound": "Sound detected",
|
||||
"doorbell_chime": "Doorbell pressed"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml": {
|
||||
"description": "Configuring Nest in configuration.yaml is being removed in Home Assistant 2022.10.\n\nYour existing OAuth Application Credentials and access settings have been imported into the UI automatically. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
|
||||
"title": "The Nest YAML configuration is being removed"
|
||||
},
|
||||
"removed_app_auth": {
|
||||
"description": "To improve security and reduce phishing risk Google has deprecated the authentication method used by Home Assistant.\n\n**This requires action by you to resolve** ([more info]({more_info_url}))\n\n1. Visit the integrations page\n1. Click Reconfigure on the Nest integration.\n1. Home Assistant will walk you through the steps to upgrade to Web Authentication.\n\nSee the Nest [integration instructions]({documentation_url}) for troubleshooting information.",
|
||||
"title": "Nest Authentication Credentials must be updated"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "NextDNS",
|
||||
"documentation": "https://www.home-assistant.io/integrations/nextdns",
|
||||
"codeowners": ["@bieniu"],
|
||||
"requirements": ["nextdns==1.0.1"],
|
||||
"requirements": ["nextdns==1.0.2"],
|
||||
"config_flow": true,
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["nextdns"]
|
||||
|
||||
@@ -135,7 +135,7 @@ SENSORS: tuple[NextDnsSensorEntityDescription, ...] = (
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:dns",
|
||||
name="TCP Queries",
|
||||
name="TCP queries",
|
||||
native_unit_of_measurement="queries",
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
value=lambda data: data.tcp_queries,
|
||||
@@ -190,7 +190,7 @@ SENSORS: tuple[NextDnsSensorEntityDescription, ...] = (
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:dns",
|
||||
name="TCP Queries Ratio",
|
||||
name="TCP queries ratio",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value=lambda data: data.tcp_queries_ratio,
|
||||
|
||||
@@ -3,6 +3,8 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import traceback
|
||||
from typing import Any
|
||||
|
||||
from aionotion import async_get_client
|
||||
@@ -31,7 +33,6 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
ATTR_SYSTEM_MODE = "system_mode"
|
||||
ATTR_SYSTEM_NAME = "system_name"
|
||||
|
||||
DEFAULT_ATTRIBUTION = "Data provided by Notion"
|
||||
DEFAULT_SCAN_INTERVAL = timedelta(minutes=1)
|
||||
|
||||
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
||||
@@ -75,6 +76,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
f"There was a Notion error while updating {attr}: {result}"
|
||||
) from result
|
||||
if isinstance(result, Exception):
|
||||
if LOGGER.isEnabledFor(logging.DEBUG):
|
||||
LOGGER.debug("".join(traceback.format_tb(result.__traceback__)))
|
||||
raise UpdateFailed(
|
||||
f"There was an unknown error while updating {attr}: {result}"
|
||||
) from result
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"""Support for OpenTherm Gateway devices."""
|
||||
import asyncio
|
||||
from datetime import date, datetime
|
||||
import logging
|
||||
|
||||
import pyotgw
|
||||
import pyotgw.vars as gw_vars
|
||||
from serial import SerialException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
@@ -23,6 +25,7 @@ from homeassistant.const import (
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@@ -37,6 +40,7 @@ from .const import (
|
||||
CONF_PRECISION,
|
||||
CONF_READ_PRECISION,
|
||||
CONF_SET_PRECISION,
|
||||
CONNECTION_TIMEOUT,
|
||||
DATA_GATEWAYS,
|
||||
DATA_OPENTHERM_GW,
|
||||
DOMAIN,
|
||||
@@ -107,8 +111,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
config_entry.add_update_listener(options_updated)
|
||||
|
||||
# Schedule directly on the loop to avoid blocking HA startup.
|
||||
hass.loop.create_task(gateway.connect_and_subscribe())
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
gateway.connect_and_subscribe(),
|
||||
timeout=CONNECTION_TIMEOUT,
|
||||
)
|
||||
except (asyncio.TimeoutError, ConnectionError, SerialException) as ex:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Could not connect to gateway at {gateway.device_path}: {ex}"
|
||||
) from ex
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
@@ -428,6 +439,9 @@ class OpenThermGatewayDevice:
|
||||
async def connect_and_subscribe(self):
|
||||
"""Connect to serial device and subscribe report handler."""
|
||||
self.status = await self.gateway.connect(self.device_path)
|
||||
if not self.status:
|
||||
await self.cleanup()
|
||||
raise ConnectionError
|
||||
version_string = self.status[gw_vars.OTGW].get(gw_vars.OTGW_ABOUT)
|
||||
self.gw_version = version_string[18:] if version_string else None
|
||||
_LOGGER.debug(
|
||||
|
||||
@@ -26,6 +26,7 @@ from .const import (
|
||||
CONF_READ_PRECISION,
|
||||
CONF_SET_PRECISION,
|
||||
CONF_TEMPORARY_OVRD_MODE,
|
||||
CONNECTION_TIMEOUT,
|
||||
)
|
||||
|
||||
|
||||
@@ -62,15 +63,21 @@ class OpenThermGwConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
otgw = pyotgw.OpenThermGateway()
|
||||
status = await otgw.connect(device)
|
||||
await otgw.disconnect()
|
||||
if not status:
|
||||
raise ConnectionError
|
||||
return status[gw_vars.OTGW].get(gw_vars.OTGW_ABOUT)
|
||||
|
||||
try:
|
||||
res = await asyncio.wait_for(test_connection(), timeout=10)
|
||||
except (asyncio.TimeoutError, SerialException):
|
||||
await asyncio.wait_for(
|
||||
test_connection(),
|
||||
timeout=CONNECTION_TIMEOUT,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
return self._show_form({"base": "timeout_connect"})
|
||||
except (ConnectionError, SerialException):
|
||||
return self._show_form({"base": "cannot_connect"})
|
||||
|
||||
if res:
|
||||
return self._create_entry(gw_id, name, device)
|
||||
return self._create_entry(gw_id, name, device)
|
||||
|
||||
return self._show_form()
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ CONF_READ_PRECISION = "read_precision"
|
||||
CONF_SET_PRECISION = "set_precision"
|
||||
CONF_TEMPORARY_OVRD_MODE = "temporary_override_mode"
|
||||
|
||||
CONNECTION_TIMEOUT = 10
|
||||
|
||||
DATA_GATEWAYS = "gateways"
|
||||
DATA_OPENTHERM_GW = "opentherm_gw"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "opentherm_gw",
|
||||
"name": "OpenTherm Gateway",
|
||||
"documentation": "https://www.home-assistant.io/integrations/opentherm_gw",
|
||||
"requirements": ["pyotgw==2.0.1"],
|
||||
"requirements": ["pyotgw==2.0.2"],
|
||||
"codeowners": ["@mvn23"],
|
||||
"config_flow": true,
|
||||
"iot_class": "local_push",
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
"error": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"id_exists": "Gateway id already exists",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"timeout_connect": "[%key:common::config_flow::error::timeout_connect%]"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"domain": "overkiz",
|
||||
"name": "Overkiz (by Somfy)",
|
||||
"name": "Overkiz",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/overkiz",
|
||||
"requirements": ["pyoverkiz==1.4.2"],
|
||||
|
||||
@@ -38,15 +38,22 @@ LOGGER = logging.getLogger(__name__)
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Philips TV from a config entry."""
|
||||
|
||||
system: SystemType | None = entry.data.get(CONF_SYSTEM)
|
||||
tvapi = PhilipsTV(
|
||||
entry.data[CONF_HOST],
|
||||
entry.data[CONF_API_VERSION],
|
||||
username=entry.data.get(CONF_USERNAME),
|
||||
password=entry.data.get(CONF_PASSWORD),
|
||||
system=system,
|
||||
)
|
||||
coordinator = PhilipsTVDataUpdateCoordinator(hass, tvapi, entry.options)
|
||||
|
||||
await coordinator.async_refresh()
|
||||
|
||||
if (actual_system := tvapi.system) and actual_system != system:
|
||||
data = {**entry.data, CONF_SYSTEM: actual_system}
|
||||
hass.config_entries.async_update_entry(entry, data=data)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ class RainMachineEntity(CoordinatorEntity):
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
"""When entity is added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
self.update_from_latest_data()
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||
name="Hourly restrictions",
|
||||
icon="mdi:cancel",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||
data_key="hourly",
|
||||
),
|
||||
@@ -86,7 +85,6 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||
name="Month restrictions",
|
||||
icon="mdi:cancel",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||
data_key="month",
|
||||
),
|
||||
@@ -95,7 +93,6 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||
name="Rain delay restrictions",
|
||||
icon="mdi:cancel",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||
data_key="rainDelay",
|
||||
),
|
||||
@@ -113,7 +110,6 @@ BINARY_SENSOR_DESCRIPTIONS = (
|
||||
name="Weekday restrictions",
|
||||
icon="mdi:cancel",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
api_category=DATA_RESTRICTIONS_CURRENT,
|
||||
data_key="weekDay",
|
||||
),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Risco",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/risco",
|
||||
"requirements": ["pyrisco==0.5.0"],
|
||||
"requirements": ["pyrisco==0.5.2"],
|
||||
"codeowners": ["@OnFreund"],
|
||||
"quality_scale": "platinum",
|
||||
"iot_class": "cloud_polling",
|
||||
|
||||
@@ -13,6 +13,7 @@ from homeassistant.components.binary_sensor import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -35,6 +36,7 @@ class RaspberryChargerBinarySensor(BinarySensorEntity):
|
||||
"""Binary sensor representing the rpi power status."""
|
||||
|
||||
_attr_device_class = BinarySensorDeviceClass.PROBLEM
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_icon = "mdi:raspberry-pi"
|
||||
_attr_name = "RPi Power status"
|
||||
_attr_unique_id = "rpi_power" # only one sensor possible
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user