core/tests/components/overkiz/test_init.py

91 lines
3.8 KiB
Python
Raw Normal View History

"""Tests for Overkiz integration init."""
from homeassistant.components.overkiz.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
Add local API support to Overkiz integration (Somfy TaHoma Developer Mode) (#71644) * Add initial config flow implementation * Add initial config flow implementation * Add todos * Bugfixes * Add first zeroconf code * Fixes for new firmware * Bugfixes for local integration * Delete local token * Fix diagnostics * Update translations and improve code * Update translations and improve code * Add local integration updates * Add local integration updates * Small tweaks * Add comments * Bugfix * Small code improvements * Small code improvements * Small code improvements * Small code improvements * Small code improvements * Small code improvements * Bugfixes * Small code improvements * Small code improvements * Change Config Flow (breaking change) * Remove token when integration is unloaded * Remove print * Simplify * Bugfixes * Improve configflow * Clean up unnecessary things * Catch nosuchtoken exception * Add migration for Config Flow * Add version 2 migration * Revert change in Config Flow * Fix api type * Update strings * Improve migrate entry * Implement changes * add more comments * Extend diagnostics * Ruff fixes * Clean up code * Bugfixes * Set gateway id * Start writing tests * Add first local test * Code coverage to 64% * Fixes * Remove local token on remove entry * Add debug logging + change manifest * Add developer mode check * Fix not_such_token issue * Small text changes * Bugfix * Fix tests * Address feedback * DRY * Test coverage to 77% * Coverage to 78% * Remove token removal by UUID * Add better retry methods * Clean up * Remove old data * 87% coverage * 90% code coverage * 100% code coverage * Use patch.multiple * Improve tests * Apply pre-commit after rebase * Fix breaking changes in ZeroconfServiceInfo * Add verify_ssl * Fix test import * Fix tests * Catch SSL verify failed * Revert hub to server rename * Move Config Flow version back to 1 * Add diagnostics tests * Fix tests * Fix strings * Implement feedback * Add debug logging for local connection errors * Simplify Config Flow and fix tests * Simplify Config Flow * Fix verify_ssl * Fix rebase mistake * Address feedback * Apply suggestions from code review * Update tests/components/overkiz/test_config_flow.py --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-11-22 15:53:17 +00:00
from .test_config_flow import TEST_EMAIL, TEST_GATEWAY_ID, TEST_PASSWORD, TEST_SERVER
from tests.common import MockConfigEntry, mock_registry
ENTITY_SENSOR_DISCRETE_RSSI_LEVEL = "sensor.zipscreen_woonkamer_discrete_rssi_level"
ENTITY_ALARM_CONTROL_PANEL = "alarm_control_panel.alarm"
ENTITY_SWITCH_GARAGE = "switch.garage"
ENTITY_SENSOR_TARGET_CLOSURE_STATE = "sensor.zipscreen_woonkamer_target_closure_state"
ENTITY_SENSOR_TARGET_CLOSURE_STATE_2 = (
"sensor.zipscreen_woonkamer_target_closure_state_2"
)
async def test_unique_id_migration(hass: HomeAssistant) -> None:
"""Test migration of sensor unique IDs."""
mock_entry = MockConfigEntry(
domain=DOMAIN,
unique_id=TEST_GATEWAY_ID,
Add local API support to Overkiz integration (Somfy TaHoma Developer Mode) (#71644) * Add initial config flow implementation * Add initial config flow implementation * Add todos * Bugfixes * Add first zeroconf code * Fixes for new firmware * Bugfixes for local integration * Delete local token * Fix diagnostics * Update translations and improve code * Update translations and improve code * Add local integration updates * Add local integration updates * Small tweaks * Add comments * Bugfix * Small code improvements * Small code improvements * Small code improvements * Small code improvements * Small code improvements * Small code improvements * Bugfixes * Small code improvements * Small code improvements * Change Config Flow (breaking change) * Remove token when integration is unloaded * Remove print * Simplify * Bugfixes * Improve configflow * Clean up unnecessary things * Catch nosuchtoken exception * Add migration for Config Flow * Add version 2 migration * Revert change in Config Flow * Fix api type * Update strings * Improve migrate entry * Implement changes * add more comments * Extend diagnostics * Ruff fixes * Clean up code * Bugfixes * Set gateway id * Start writing tests * Add first local test * Code coverage to 64% * Fixes * Remove local token on remove entry * Add debug logging + change manifest * Add developer mode check * Fix not_such_token issue * Small text changes * Bugfix * Fix tests * Address feedback * DRY * Test coverage to 77% * Coverage to 78% * Remove token removal by UUID * Add better retry methods * Clean up * Remove old data * 87% coverage * 90% code coverage * 100% code coverage * Use patch.multiple * Improve tests * Apply pre-commit after rebase * Fix breaking changes in ZeroconfServiceInfo * Add verify_ssl * Fix test import * Fix tests * Catch SSL verify failed * Revert hub to server rename * Move Config Flow version back to 1 * Add diagnostics tests * Fix tests * Fix strings * Implement feedback * Add debug logging for local connection errors * Simplify Config Flow and fix tests * Simplify Config Flow * Fix verify_ssl * Fix rebase mistake * Address feedback * Apply suggestions from code review * Update tests/components/overkiz/test_config_flow.py --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-11-22 15:53:17 +00:00
data={"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_SERVER},
)
mock_entry.add_to_hass(hass)
mock_registry(
hass,
{
# This entity will be migrated to "io://1234-5678-1234/3541212-core:DiscreteRSSILevelState"
ENTITY_SENSOR_DISCRETE_RSSI_LEVEL: er.RegistryEntry(
entity_id=ENTITY_SENSOR_DISCRETE_RSSI_LEVEL,
unique_id="io://1234-5678-1234/3541212-OverkizState.CORE_DISCRETE_RSSI_LEVEL",
platform=DOMAIN,
config_entry_id=mock_entry.entry_id,
),
# This entity will be migrated to "internal://1234-5678-1234/alarm/0-TSKAlarmController"
ENTITY_ALARM_CONTROL_PANEL: er.RegistryEntry(
entity_id=ENTITY_ALARM_CONTROL_PANEL,
unique_id="internal://1234-5678-1234/alarm/0-UIWidget.TSKALARM_CONTROLLER",
platform=DOMAIN,
config_entry_id=mock_entry.entry_id,
),
# This entity will be migrated to "io://1234-5678-1234/0-OnOff"
ENTITY_SWITCH_GARAGE: er.RegistryEntry(
entity_id=ENTITY_SWITCH_GARAGE,
unique_id="io://1234-5678-1234/0-UIClass.ON_OFF",
platform=DOMAIN,
config_entry_id=mock_entry.entry_id,
),
# This entity will be removed since "io://1234-5678-1234/3541212-core:TargetClosureState" already exists
ENTITY_SENSOR_TARGET_CLOSURE_STATE: er.RegistryEntry(
entity_id=ENTITY_SENSOR_TARGET_CLOSURE_STATE,
unique_id="io://1234-5678-1234/3541212-OverkizState.CORE_TARGET_CLOSURE",
platform=DOMAIN,
config_entry_id=mock_entry.entry_id,
),
# This entity will not be migrated"
ENTITY_SENSOR_TARGET_CLOSURE_STATE_2: er.RegistryEntry(
entity_id=ENTITY_SENSOR_TARGET_CLOSURE_STATE_2,
unique_id="io://1234-5678-1234/3541212-core:TargetClosureState",
platform=DOMAIN,
config_entry_id=mock_entry.entry_id,
),
},
)
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
ent_reg = er.async_get(hass)
unique_id_map = {
ENTITY_SENSOR_DISCRETE_RSSI_LEVEL: "io://1234-5678-1234/3541212-core:DiscreteRSSILevelState",
ENTITY_ALARM_CONTROL_PANEL: "internal://1234-5678-1234/alarm/0-TSKAlarmController",
ENTITY_SWITCH_GARAGE: "io://1234-5678-1234/0-OnOff",
ENTITY_SENSOR_TARGET_CLOSURE_STATE_2: "io://1234-5678-1234/3541212-core:TargetClosureState",
}
# Test if entities will be removed
assert set(ent_reg.entities.keys()) == set(unique_id_map)
# Test if unique ids are migrated
for entity_id, unique_id in unique_id_map.items():
entry = ent_reg.async_get(entity_id)
assert entry.unique_id == unique_id