core/homeassistant/components/rabbitair/config_flow.py

126 lines
4.2 KiB
Python
Raw Normal View History

Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
"""Config flow for Rabbit Air integration."""
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
from __future__ import annotations
import logging
from typing import Any
from rabbitair import UdpClient
import voluptuous as vol
from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_MAC
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
"""Validate the user input allows us to connect."""
try:
try:
zeroconf_instance = await zeroconf.async_get_async_instance(hass)
with UdpClient(
data[CONF_HOST], data[CONF_ACCESS_TOKEN], zeroconf=zeroconf_instance
) as client:
info = await client.get_info()
except Exception as err:
_LOGGER.debug("Connection attempt failed: %s", err)
raise
except ValueError as err:
# Most likely caused by the invalid access token.
raise InvalidAccessToken from err
except TimeoutError as err:
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
# Either the host doesn't respond or the auth failed.
raise TimeoutConnect from err
except OSError as err:
# Most likely caused by the invalid host.
raise InvalidHost from err
except Exception as err:
# Other possible errors.
raise CannotConnect from err
# Return info to store in the config entry.
return {"mac": info.mac}
class RabbitAirConfigFlow(ConfigFlow, domain=DOMAIN):
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
"""Handle a config flow for Rabbit Air."""
VERSION = 1
_discovered_host: str | None = None
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
"""Handle the initial step."""
errors = {}
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAccessToken:
errors["base"] = "invalid_access_token"
except InvalidHost:
errors["base"] = "invalid_host"
except TimeoutConnect:
errors["base"] = "timeout_connect"
except Exception as err: # noqa: BLE001
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
_LOGGER.debug("Unexpected exception: %s", err)
errors["base"] = "unknown"
else:
user_input[CONF_MAC] = info["mac"]
await self.async_set_unique_id(dr.format_mac(info["mac"]))
self._abort_if_unique_id_configured(updates=user_input)
return self.async_create_entry(title="Rabbit Air", data=user_input)
user_input = user_input or {}
host = user_input.get(CONF_HOST, self._discovered_host)
token = user_input.get(CONF_ACCESS_TOKEN)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_HOST, default=host): str,
vol.Required(CONF_ACCESS_TOKEN, default=token): vol.All(
str, vol.Length(min=32, max=32)
),
}
),
errors=errors,
)
async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> ConfigFlowResult:
Add new Rabbit Air integration (#66130) * Add new Rabbit Air integration * Remove py.typed file It is not needed and was just accidentally added to the commit. * Enable strict type checking for rabbitair component Keeping the code fully type hinted is a good idea. * Add missing type annotations * Remove translation file * Prevent data to be added to hass.data if refresh fails * Reload the config entry when the options change * Add missing type parameters for generics * Avoid using assert in production code * Move zeroconf to optional dependencies * Remove unnecessary logging Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unused keys from the manifest Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Replace property with attr Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Allow to return None for power The type of the is_on property now allows this. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Remove unnecessary method call Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update the python library The new version properly re-exports names from the package root. * Remove options flow Scan interval should not be part of integration configuration. This was the only option, so the options flow can be fully removed. * Replace properties with attrs * Remove multiline ternary operator * Use NamedTuple for hass.data * Remove unused logger variable * Move async_setup_entry up in the file * Adjust debouncer settings to use request_refresh * Prevent status updates during the cooldown period * Move device polling code to the update coordinator * Fix the problem with the switch jumping back and forth The UI seems to have a timeout of 2 seconds somewhere, which is just a little bit less than what we normally need to get an updated state. So the power switch would jump to its previous state and then immediately return to the new state. * Update the python library The new version fixes errors when multiple requests are executed simultaneously. * Fix incorrect check for pending call in debouncer This caused the polling to stop. * Fix tests * Update .coveragerc to exclude new file. * Remove test for Options Flow. * Update the existing entry when device access details change * Add Zeroconf discovery step * Fix tests The ZeroconfServiceInfo constructor now requires one more argument. * Fix typing for CoordinatorEntity * Fix signature of async_turn_on * Fix depreciation warnings * Fix manifest formatting * Fix warning about debouncer typing relates to 5ae5ae5392729b4c94a8004bd02e147d60227341 * Wait for config entry platform forwards * Apply some of the suggested changes * Do not put the MAC address in the title. Use a fixed title instead. * Do not format the MAC to use as a unique ID. * Do not catch exceptions in _async_update_data(). * Remove unused _entry field in the base entity class. * Use the standard attribute self._attr_is_on to keep the power state. * Store the MAC in the config entry data * Change the order of except clauses OSError is an ancestor class of TimeoutError, so TimeoutError should be handled first * Fix depreciation warnings * Fix tests The ZeroconfServiceInfo constructor arguments have changed. * Fix DeviceInfo import * Rename the method to make it clearer what it does * Apply suggestions from code review * Fix tests * Change speed/mode logic to use is_on from the base class * A zero value is more appropriate than None since None means "unknown", but we actually know that the speed is zero when the power is off. --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-05 15:34:28 +00:00
"""Handle zeroconf discovery."""
mac = dr.format_mac(discovery_info.properties["id"])
await self.async_set_unique_id(mac)
self._abort_if_unique_id_configured()
self._discovered_host = discovery_info.hostname.rstrip(".")
return await self.async_step_user()
class CannotConnect(HomeAssistantError):
"""Error to indicate we cannot connect."""
class InvalidAccessToken(HomeAssistantError):
"""Error to indicate the access token is not valid."""
class InvalidHost(HomeAssistantError):
"""Error to indicate the host is not valid."""
class TimeoutConnect(HomeAssistantError):
"""Error to indicate the connection attempt is timed out."""