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:
1 parent
2123f6f133
commit
c87ecf0ff6
22 files changed
+1403
-271
No files matched your search
@@ -0,0 +1,83 @@
|
||||
"""Tests for AVM Fritz!Box sensor component."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import Mock
|
||||
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
from homeassistant.components.fritzbox.const import (
|
||||
ATTR_STATE_DEVICE_LOCKED,
|
||||
ATTR_STATE_LOCKED,
|
||||
DOMAIN as FB_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from . import MOCK_CONFIG, FritzDeviceSensorMock
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
ENTITY_ID = f"{DOMAIN}.fake_name"
|
||||
|
||||
|
||||
async def setup_fritzbox(hass: HomeAssistantType, config: dict):
|
||||
"""Set up mock AVM Fritz!Box."""
|
||||
assert await async_setup_component(hass, FB_DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_setup(hass: HomeAssistantType, fritz: Mock):
|
||||
"""Test setup of platform."""
|
||||
device = FritzDeviceSensorMock()
|
||||
fritz().get_devices.return_value = [device]
|
||||
|
||||
await setup_fritzbox(hass, MOCK_CONFIG)
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
|
||||
assert state
|
||||
assert state.state == "1.23"
|
||||
assert state.attributes[ATTR_FRIENDLY_NAME] == "fake_name"
|
||||
assert state.attributes[ATTR_STATE_DEVICE_LOCKED] == "fake_locked_device"
|
||||
assert state.attributes[ATTR_STATE_LOCKED] == "fake_locked"
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == TEMP_CELSIUS
|
||||
|
||||
|
||||
async def test_update(hass: HomeAssistantType, fritz: Mock):
|
||||
"""Test update with error."""
|
||||
device = FritzDeviceSensorMock()
|
||||
fritz().get_devices.return_value = [device]
|
||||
|
||||
await setup_fritzbox(hass, MOCK_CONFIG)
|
||||
assert device.update.call_count == 0
|
||||
assert fritz().login.call_count == 1
|
||||
|
||||
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert device.update.call_count == 1
|
||||
assert fritz().login.call_count == 1
|
||||
|
||||
|
||||
async def test_update_error(hass: HomeAssistantType, fritz: Mock):
|
||||
"""Test update with error."""
|
||||
device = FritzDeviceSensorMock()
|
||||
device.update.side_effect = HTTPError("Boom")
|
||||
fritz().get_devices.return_value = [device]
|
||||
|
||||
await setup_fritzbox(hass, MOCK_CONFIG)
|
||||
assert device.update.call_count == 0
|
||||
assert fritz().login.call_count == 1
|
||||
|
||||
next_update = dt_util.utcnow() + timedelta(seconds=200)
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert device.update.call_count == 1
|
||||
assert fritz().login.call_count == 2
|
||||
Reference in new issue
Block a user