Add config flow and device registry to fritzbox integration (#31240)
* add config flow * fix pylint * update lib * Update config_flow.py * remote devices layer in config * add default host * avoid double setups of entities * remove async_setup_platform * store entities in hass.data * pass fritz connection together with config_entry * fritz connections try no4 (or is it even more) * fix comments * add unloading * fixed comments * Update config_flow.py * Update const.py * Update config_flow.py * Update __init__.py * Update config_flow.py * Update __init__.py * Update __init__.py * Update config_flow.py * Update __init__.py * Update __init__.py * Update __init__.py * Update config_flow.py * add init tests * test unloading * add switch tests * add sensor tests * add climate tests * test target temperature * mock config to package * comments * test binary sensor state * add config flow tests * comments * add missing tests * minor * remove string title * deprecate yaml * don't change yaml * get devices async * minor * add devices again * comments fixed * unique_id fixes * fix patches * Fix schema Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
2123f6f133
commit
c87ecf0ff6
22 changed files with 1403 additions and 271 deletions
|
@ -1,6 +1,4 @@
|
|||
"""Support for AVM Fritz!Box smarthome thermostate devices."""
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
|
@ -16,22 +14,23 @@ from homeassistant.components.climate.const import (
|
|||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_DEVICES,
|
||||
PRECISION_HALVES,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
|
||||
from . import (
|
||||
from .const import (
|
||||
ATTR_STATE_BATTERY_LOW,
|
||||
ATTR_STATE_DEVICE_LOCKED,
|
||||
ATTR_STATE_HOLIDAY_MODE,
|
||||
ATTR_STATE_LOCKED,
|
||||
ATTR_STATE_SUMMER_MODE,
|
||||
ATTR_STATE_WINDOW_OPEN,
|
||||
CONF_CONNECTIONS,
|
||||
DOMAIN as FRITZBOX_DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
||||
|
||||
OPERATION_LIST = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
||||
|
@ -48,18 +47,18 @@ ON_REPORT_SET_TEMPERATURE = 30.0
|
|||
OFF_REPORT_SET_TEMPERATURE = 0.0
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Fritzbox smarthome thermostat platform."""
|
||||
devices = []
|
||||
fritz_list = hass.data[FRITZBOX_DOMAIN]
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Fritzbox smarthome thermostat from config_entry."""
|
||||
entities = []
|
||||
devices = hass.data[FRITZBOX_DOMAIN][CONF_DEVICES]
|
||||
fritz = hass.data[FRITZBOX_DOMAIN][CONF_CONNECTIONS][config_entry.entry_id]
|
||||
|
||||
for fritz in fritz_list:
|
||||
device_list = fritz.get_devices()
|
||||
for device in device_list:
|
||||
if device.has_thermostat:
|
||||
devices.append(FritzboxThermostat(device, fritz))
|
||||
for device in await hass.async_add_executor_job(fritz.get_devices):
|
||||
if device.has_thermostat and device.ain not in devices:
|
||||
entities.append(FritzboxThermostat(device, fritz))
|
||||
devices.add(device.ain)
|
||||
|
||||
add_entities(devices)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class FritzboxThermostat(ClimateDevice):
|
||||
|
@ -74,6 +73,22 @@ class FritzboxThermostat(ClimateDevice):
|
|||
self._comfort_temperature = self._device.comfort_temperature
|
||||
self._eco_temperature = self._device.eco_temperature
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return device specific attributes."""
|
||||
return {
|
||||
"name": self.name,
|
||||
"identifiers": {(FRITZBOX_DOMAIN, self._device.ain)},
|
||||
"manufacturer": self._device.manufacturer,
|
||||
"model": self._device.productname,
|
||||
"sw_version": self._device.fw_version,
|
||||
}
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID of the device."""
|
||||
return self._device.ain
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
|
@ -205,5 +220,5 @@ class FritzboxThermostat(ClimateDevice):
|
|||
self._comfort_temperature = self._device.comfort_temperature
|
||||
self._eco_temperature = self._device.eco_temperature
|
||||
except requests.exceptions.HTTPError as ex:
|
||||
_LOGGER.warning("Fritzbox connection error: %s", ex)
|
||||
LOGGER.warning("Fritzbox connection error: %s", ex)
|
||||
self._fritz.login()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue