diff --git a/homeassistant/components/switcher_kis/config_flow.py b/homeassistant/components/switcher_kis/config_flow.py index e6c2e8e8589..2e4b3478e8c 100644 --- a/homeassistant/components/switcher_kis/config_flow.py +++ b/homeassistant/components/switcher_kis/config_flow.py @@ -21,8 +21,8 @@ _LOGGER = logging.getLogger(__name__) CONFIG_SCHEMA: Final = vol.Schema( { - vol.Required(CONF_USERNAME, default=""): str, - vol.Required(CONF_TOKEN, default=""): str, + vol.Required(CONF_USERNAME): str, + vol.Required(CONF_TOKEN): str, } ) @@ -32,9 +32,12 @@ class SwitcherFlowHandler(ConfigFlow, domain=DOMAIN): VERSION = 1 - username: str | None = None - token: str | None = None - discovered_devices: dict[str, SwitcherBase] = {} + def __init__(self) -> None: + """Init the config flow.""" + super().__init__() + self.discovered_devices: dict[str, SwitcherBase] = {} + self.username: str | None = None + self.token: str | None = None async def async_step_user( self, user_input: dict[str, Any] | None = None diff --git a/homeassistant/components/switcher_kis/light.py b/homeassistant/components/switcher_kis/light.py index b9dc78f5bdf..472b89cdec7 100644 --- a/homeassistant/components/switcher_kis/light.py +++ b/homeassistant/components/switcher_kis/light.py @@ -59,6 +59,16 @@ class SwitcherBaseLightEntity(SwitcherEntity, LightEntity): control_result: bool | None = None _light_id: int + def __init__( + self, + coordinator: SwitcherDataUpdateCoordinator, + light_id: int, + ) -> None: + """Initialize the entity.""" + super().__init__(coordinator) + self._light_id = light_id + self.control_result: bool | None = None + @callback def _handle_coordinator_update(self) -> None: """When device updates, clear control result that overrides state.""" @@ -98,9 +108,7 @@ class SwitcherSingleLightEntity(SwitcherBaseLightEntity): light_id: int, ) -> None: """Initialize the entity.""" - super().__init__(coordinator) - self._light_id = light_id - self.control_result: bool | None = None + super().__init__(coordinator, light_id) # Entity class attributes self._attr_unique_id = f"{coordinator.device_id}-{coordinator.mac_address}" @@ -117,9 +125,7 @@ class SwitcherMultiLightEntity(SwitcherBaseLightEntity): light_id: int, ) -> None: """Initialize the entity.""" - super().__init__(coordinator) - self._light_id = light_id - self.control_result: bool | None = None + super().__init__(coordinator, light_id) # Entity class attributes self._attr_translation_placeholders = {"light_id": str(light_id + 1)} diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index 30b0b4161b1..6111ab71909 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -6,8 +6,13 @@ from datetime import timedelta import logging from typing import Any, cast -from aioswitcher.api import Command, ShutterChildLock -from aioswitcher.device import DeviceCategory, DeviceState, SwitcherShutter +from aioswitcher.api import Command +from aioswitcher.device import ( + DeviceCategory, + DeviceState, + ShutterChildLock, + SwitcherShutter, +) import voluptuous as vol from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity @@ -83,11 +88,11 @@ async def async_setup_entry( number_of_covers = len(cast(SwitcherShutter, coordinator.data).position) if number_of_covers == 1: entities.append( - SwitchereShutterChildLockSingleSwitchEntity(coordinator, 0) + SwitcherShutterChildLockSingleSwitchEntity(coordinator, 0) ) else: entities.extend( - SwitchereShutterChildLockMultiSwitchEntity(coordinator, i) + SwitcherShutterChildLockMultiSwitchEntity(coordinator, i) for i in range(number_of_covers) ) async_add_entities(entities) @@ -176,7 +181,7 @@ class SwitcherWaterHeaterSwitchEntity(SwitcherBaseSwitchEntity): self.async_write_ha_state() -class SwitchereShutterChildLockBaseSwitchEntity(SwitcherEntity, SwitchEntity): +class SwitcherShutterChildLockBaseSwitchEntity(SwitcherEntity, SwitchEntity): """Representation of a Switcher shutter base switch entity.""" _attr_device_class = SwitchDeviceClass.SWITCH @@ -221,8 +226,8 @@ class SwitchereShutterChildLockBaseSwitchEntity(SwitcherEntity, SwitchEntity): self.async_write_ha_state() -class SwitchereShutterChildLockSingleSwitchEntity( - SwitchereShutterChildLockBaseSwitchEntity +class SwitcherShutterChildLockSingleSwitchEntity( + SwitcherShutterChildLockBaseSwitchEntity ): """Representation of a Switcher runner child lock single switch entity.""" @@ -242,8 +247,8 @@ class SwitchereShutterChildLockSingleSwitchEntity( ) -class SwitchereShutterChildLockMultiSwitchEntity( - SwitchereShutterChildLockBaseSwitchEntity +class SwitcherShutterChildLockMultiSwitchEntity( + SwitcherShutterChildLockBaseSwitchEntity ): """Representation of a Switcher runner child lock multiple switch entity.""" diff --git a/tests/components/switcher_kis/test_init.py b/tests/components/switcher_kis/test_init.py index a652348463e..8cf947a1596 100644 --- a/tests/components/switcher_kis/test_init.py +++ b/tests/components/switcher_kis/test_init.py @@ -2,6 +2,7 @@ from datetime import timedelta +from freezegun.api import FrozenDateTimeFactory import pytest from homeassistant.components.switcher_kis.const import DOMAIN, MAX_UPDATE_INTERVAL_SEC @@ -20,7 +21,10 @@ from tests.typing import WebSocketGenerator async def test_update_fail( - hass: HomeAssistant, mock_bridge, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, + mock_bridge, + caplog: pytest.LogCaptureFixture, + freezer: FrozenDateTimeFactory, ) -> None: """Test entities state unavailable when updates fail..""" entry = await init_integration(hass) @@ -32,9 +36,8 @@ async def test_update_fail( assert mock_bridge.is_running is True assert len(entry.runtime_data) == 2 - async_fire_time_changed( - hass, dt_util.utcnow() + timedelta(seconds=MAX_UPDATE_INTERVAL_SEC + 1) - ) + freezer.tick(timedelta(seconds=MAX_UPDATE_INTERVAL_SEC + 1)) + async_fire_time_changed(hass) await hass.async_block_till_done() for device in DUMMY_SWITCHER_DEVICES: diff --git a/tests/components/switcher_kis/test_sensor.py b/tests/components/switcher_kis/test_sensor.py index f99d91bd9a3..aedc004859f 100644 --- a/tests/components/switcher_kis/test_sensor.py +++ b/tests/components/switcher_kis/test_sensor.py @@ -3,7 +3,6 @@ import pytest from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry as er from homeassistant.util import slugify from . import init_integration @@ -55,35 +54,6 @@ async def test_sensor_platform(hass: HomeAssistant, mock_bridge) -> None: assert state.state == str(getattr(device, field)) -async def test_sensor_disabled( - hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_bridge -) -> None: - """Test sensor disabled by default.""" - await init_integration(hass) - assert mock_bridge - - mock_bridge.mock_callbacks([DUMMY_WATER_HEATER_DEVICE]) - await hass.async_block_till_done() - - device = DUMMY_WATER_HEATER_DEVICE - unique_id = f"{device.device_id}-{device.mac_address}-auto_off_set" - entity_id = f"sensor.{slugify(device.name)}_auto_shutdown" - entry = entity_registry.async_get(entity_id) - - assert entry - assert entry.unique_id == unique_id - assert entry.disabled is True - assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION - - # Test enabling entity - updated_entry = entity_registry.async_update_entity( - entry.entity_id, disabled_by=None - ) - - assert updated_entry != entry - assert updated_entry.disabled is False - - @pytest.mark.parametrize("mock_bridge", [[DUMMY_WATER_HEATER_DEVICE]], indirect=True) async def test_sensor_update( hass: HomeAssistant, mock_bridge, monkeypatch: pytest.MonkeyPatch