-
-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'home-assistant:dev' into verisure_trust
- Loading branch information
Showing
185 changed files
with
6,548 additions
and
1,133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.0.280 | ||
rev: v0.0.285 | ||
hooks: | ||
- id: ruff | ||
args: | ||
|
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Comelit integration.""" | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import CONF_HOST, CONF_PIN, Platform | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .const import DOMAIN | ||
from .coordinator import ComelitSerialBridge | ||
|
||
PLATFORMS = [Platform.LIGHT] | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Set up Comelit platform.""" | ||
coordinator = ComelitSerialBridge(hass, entry.data[CONF_HOST], entry.data[CONF_PIN]) | ||
|
||
await coordinator.async_config_entry_first_refresh() | ||
|
||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): | ||
coordinator: ComelitSerialBridge = hass.data[DOMAIN][entry.entry_id] | ||
await coordinator.api.logout() | ||
await coordinator.api.close() | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
|
||
return unload_ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
"""Config flow for Comelit integration.""" | ||
from __future__ import annotations | ||
|
||
from collections.abc import Mapping | ||
from typing import Any | ||
|
||
from aiocomelit import ComeliteSerialBridgeAPi, exceptions as aiocomelit_exceptions | ||
import voluptuous as vol | ||
|
||
from homeassistant import core, exceptions | ||
from homeassistant.config_entries import ConfigEntry, ConfigFlow | ||
from homeassistant.const import CONF_HOST, CONF_PIN | ||
from homeassistant.data_entry_flow import FlowResult | ||
|
||
from .const import _LOGGER, DOMAIN | ||
|
||
DEFAULT_HOST = "192.168.1.252" | ||
DEFAULT_PIN = "111111" | ||
|
||
|
||
def user_form_schema(user_input: dict[str, Any] | None) -> vol.Schema: | ||
"""Return user form schema.""" | ||
user_input = user_input or {} | ||
return vol.Schema( | ||
{ | ||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): str, | ||
vol.Optional(CONF_PIN, default=DEFAULT_PIN): str, | ||
} | ||
) | ||
|
||
|
||
STEP_REAUTH_DATA_SCHEMA = vol.Schema({vol.Required(CONF_PIN): str}) | ||
|
||
|
||
async def validate_input( | ||
hass: core.HomeAssistant, data: dict[str, Any] | ||
) -> dict[str, str]: | ||
"""Validate the user input allows us to connect.""" | ||
|
||
api = ComeliteSerialBridgeAPi(data[CONF_HOST], data[CONF_PIN]) | ||
|
||
try: | ||
await api.login() | ||
except aiocomelit_exceptions.CannotConnect as err: | ||
raise CannotConnect from err | ||
except aiocomelit_exceptions.CannotAuthenticate as err: | ||
raise InvalidAuth from err | ||
finally: | ||
await api.logout() | ||
await api.close() | ||
|
||
return {"title": data[CONF_HOST]} | ||
|
||
|
||
class ComelitConfigFlow(ConfigFlow, domain=DOMAIN): | ||
"""Handle a config flow for Comelit.""" | ||
|
||
VERSION = 1 | ||
_reauth_entry: ConfigEntry | None | ||
_reauth_host: str | ||
|
||
async def async_step_user( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
"""Handle the initial step.""" | ||
if user_input is None: | ||
return self.async_show_form( | ||
step_id="user", data_schema=user_form_schema(user_input) | ||
) | ||
|
||
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]}) | ||
|
||
errors = {} | ||
|
||
try: | ||
info = await validate_input(self.hass, user_input) | ||
except CannotConnect: | ||
errors["base"] = "cannot_connect" | ||
except InvalidAuth: | ||
errors["base"] = "invalid_auth" | ||
except Exception: # pylint: disable=broad-except | ||
_LOGGER.exception("Unexpected exception") | ||
errors["base"] = "unknown" | ||
else: | ||
return self.async_create_entry(title=info["title"], data=user_input) | ||
|
||
return self.async_show_form( | ||
step_id="user", data_schema=user_form_schema(user_input), errors=errors | ||
) | ||
|
||
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult: | ||
"""Handle reauth flow.""" | ||
self._reauth_entry = self.hass.config_entries.async_get_entry( | ||
self.context["entry_id"] | ||
) | ||
self._reauth_host = entry_data[CONF_HOST] | ||
self.context["title_placeholders"] = {"host": self._reauth_host} | ||
return await self.async_step_reauth_confirm() | ||
|
||
async def async_step_reauth_confirm( | ||
self, user_input: dict[str, Any] | None = None | ||
) -> FlowResult: | ||
"""Handle reauth confirm.""" | ||
assert self._reauth_entry | ||
errors = {} | ||
|
||
if user_input is not None: | ||
try: | ||
await validate_input( | ||
self.hass, {CONF_HOST: self._reauth_host} | user_input | ||
) | ||
except CannotConnect: | ||
errors["base"] = "cannot_connect" | ||
except InvalidAuth: | ||
errors["base"] = "invalid_auth" | ||
except Exception: # pylint: disable=broad-except | ||
_LOGGER.exception("Unexpected exception") | ||
errors["base"] = "unknown" | ||
else: | ||
self.hass.config_entries.async_update_entry( | ||
self._reauth_entry, | ||
data={ | ||
CONF_HOST: self._reauth_host, | ||
CONF_PIN: user_input[CONF_PIN], | ||
}, | ||
) | ||
self.hass.async_create_task( | ||
self.hass.config_entries.async_reload(self._reauth_entry.entry_id) | ||
) | ||
return self.async_abort(reason="reauth_successful") | ||
|
||
return self.async_show_form( | ||
step_id="reauth_confirm", | ||
description_placeholders={CONF_HOST: self._reauth_entry.data[CONF_HOST]}, | ||
data_schema=STEP_REAUTH_DATA_SCHEMA, | ||
errors=errors, | ||
) | ||
|
||
|
||
class CannotConnect(exceptions.HomeAssistantError): | ||
"""Error to indicate we cannot connect.""" | ||
|
||
|
||
class InvalidAuth(exceptions.HomeAssistantError): | ||
"""Error to indicate there is invalid auth.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""Comelit constants.""" | ||
import logging | ||
|
||
_LOGGER = logging.getLogger(__package__) | ||
|
||
DOMAIN = "comelit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Support for Comelit.""" | ||
import asyncio | ||
from datetime import timedelta | ||
from typing import Any | ||
|
||
from aiocomelit import ComeliteSerialBridgeAPi | ||
import aiohttp | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.exceptions import ConfigEntryAuthFailed | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed | ||
|
||
from .const import _LOGGER, DOMAIN | ||
|
||
|
||
class ComelitSerialBridge(DataUpdateCoordinator): | ||
"""Queries Comelit Serial Bridge.""" | ||
|
||
def __init__(self, hass: HomeAssistant, host: str, pin: int) -> None: | ||
"""Initialize the scanner.""" | ||
|
||
self._host = host | ||
self._pin = pin | ||
|
||
self.api = ComeliteSerialBridgeAPi(host, pin) | ||
|
||
super().__init__( | ||
hass=hass, | ||
logger=_LOGGER, | ||
name=f"{DOMAIN}-{host}-coordinator", | ||
update_interval=timedelta(seconds=5), | ||
) | ||
|
||
async def _async_update_data(self) -> dict[str, Any]: | ||
"""Update router data.""" | ||
_LOGGER.debug("Polling Comelit Serial Bridge host: %s", self._host) | ||
try: | ||
logged = await self.api.login() | ||
except (asyncio.exceptions.TimeoutError, aiohttp.ClientConnectorError) as err: | ||
_LOGGER.warning("Connection error for %s", self._host) | ||
raise UpdateFailed(f"Error fetching data: {repr(err)}") from err | ||
|
||
if not logged: | ||
raise ConfigEntryAuthFailed | ||
|
||
devices_data = await self.api.get_all_devices() | ||
alarm_data = await self.api.get_alarm_config() | ||
await self.api.logout() | ||
|
||
return devices_data | alarm_data |
Oops, something went wrong.