Skip to content

Commit

Permalink
Improve type hints in homematicip_cloud tests (#124207)
Browse files Browse the repository at this point in the history
Add missing hass type hint in homematicip_cloud tests
  • Loading branch information
epenet authored Aug 19, 2024
1 parent d9aa931 commit 197e65c
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 120 deletions.
9 changes: 4 additions & 5 deletions tests/components/homematicip_cloud/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from homematicip.base.enums import WeatherCondition, WeatherDayTime
import pytest

from homeassistant import config_entries
from homeassistant.components.homematicip_cloud import (
DOMAIN as HMIPC_DOMAIN,
async_setup as hmip_async_setup,
Expand Down Expand Up @@ -46,7 +45,7 @@ def _rest_call_side_effect(path, body=None):


@pytest.fixture(name="hmip_config_entry")
def hmip_config_entry_fixture() -> config_entries.ConfigEntry:
def hmip_config_entry_fixture() -> MockConfigEntry:
"""Create a mock config entry for homematic ip cloud."""
entry_data = {
HMIPC_HAPID: HAPID,
Expand All @@ -66,8 +65,8 @@ def hmip_config_entry_fixture() -> config_entries.ConfigEntry:

@pytest.fixture(name="default_mock_hap_factory")
async def default_mock_hap_factory_fixture(
hass: HomeAssistant, mock_connection, hmip_config_entry
) -> HomematicipHAP:
hass: HomeAssistant, mock_connection, hmip_config_entry: MockConfigEntry
) -> HomeFactory:
"""Create a mocked homematic access point."""
return HomeFactory(hass, mock_connection, hmip_config_entry)

Expand All @@ -94,7 +93,7 @@ def dummy_config_fixture() -> ConfigType:

@pytest.fixture(name="mock_hap_with_service")
async def mock_hap_with_service_fixture(
hass: HomeAssistant, default_mock_hap_factory, dummy_config
hass: HomeAssistant, default_mock_hap_factory: HomeFactory, dummy_config
) -> HomematicipHAP:
"""Create a fake homematic access point with hass services."""
mock_hap = await default_mock_hap_factory.async_get_mock_hap()
Expand Down
24 changes: 18 additions & 6 deletions tests/components/homematicip_cloud/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Helper for HomematicIP Cloud Tests."""

import json
from typing import Any
from unittest.mock import Mock, patch

from homematicip.aio.class_maps import (
Expand All @@ -11,27 +12,33 @@
from homematicip.aio.device import AsyncDevice
from homematicip.aio.group import AsyncGroup
from homematicip.aio.home import AsyncHome
from homematicip.base.homematicip_object import HomeMaticIPObject
from homematicip.home import Home

from homeassistant import config_entries
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.generic_entity import (
ATTR_IS_GROUP,
ATTR_MODEL_TYPE,
)
from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, State
from homeassistant.setup import async_setup_component

from tests.common import load_fixture
from tests.common import MockConfigEntry, load_fixture

HAPID = "3014F7110000000000000001"
HAPPIN = "5678"
AUTH_TOKEN = "1234"
FIXTURE_DATA = load_fixture("homematicip_cloud.json", "homematicip_cloud")


def get_and_check_entity_basics(hass, mock_hap, entity_id, entity_name, device_model):
def get_and_check_entity_basics(
hass: HomeAssistant,
mock_hap: HomematicipHAP,
entity_id: str,
entity_name: str,
device_model: str | None,
) -> tuple[State, HomeMaticIPObject | None]:
"""Get and test basic device."""
ha_state = hass.states.get(entity_id)
assert ha_state is not None
Expand All @@ -50,7 +57,12 @@ def get_and_check_entity_basics(hass, mock_hap, entity_id, entity_name, device_m


async def async_manipulate_test_data(
hass, hmip_device, attribute, new_value, channel=1, fire_device=None
hass: HomeAssistant,
hmip_device: HomeMaticIPObject,
attribute: str,
new_value: Any,
channel: int = 1,
fire_device: HomeMaticIPObject | None = None,
):
"""Set new value on hmip device."""
if channel == 1:
Expand All @@ -76,7 +88,7 @@ def __init__(
self,
hass: HomeAssistant,
mock_connection,
hmip_config_entry: config_entries.ConfigEntry,
hmip_config_entry: MockConfigEntry,
) -> None:
"""Initialize the Factory."""
self.hass = hass
Expand Down
14 changes: 10 additions & 4 deletions tests/components/homematicip_cloud/test_alarm_control_panel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for HomematicIP Cloud alarm control panel."""

from homematicip.aio.home import AsyncHome

from homeassistant.components.alarm_control_panel import (
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
)
Expand All @@ -13,12 +15,16 @@
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component

from .helper import get_and_check_entity_basics
from .helper import HomeFactory, get_and_check_entity_basics


async def _async_manipulate_security_zones(
hass, home, internal_active=False, external_active=False, alarm_triggered=False
):
hass: HomeAssistant,
home: AsyncHome,
internal_active: bool = False,
external_active: bool = False,
alarm_triggered: bool = False,
) -> None:
"""Set new values on hmip security zones."""
json = home._rawJSONData
json["functionalHomes"]["SECURITY_AND_ALARM"]["alarmActive"] = alarm_triggered
Expand Down Expand Up @@ -50,7 +56,7 @@ async def test_manually_configured_platform(hass: HomeAssistant) -> None:


async def test_hmip_alarm_control_panel(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipAlarmControlPanel."""
entity_id = "alarm_control_panel.hmip_alarm_control_panel"
Expand Down
42 changes: 23 additions & 19 deletions tests/components/homematicip_cloud/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component

from .helper import async_manipulate_test_data, get_and_check_entity_basics
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics


async def test_manually_configured_platform(hass: HomeAssistant) -> None:
Expand All @@ -41,7 +41,7 @@ async def test_manually_configured_platform(hass: HomeAssistant) -> None:


async def test_hmip_home_cloud_connection_sensor(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipCloudConnectionSensor."""
entity_id = "binary_sensor.cloud_connection"
Expand All @@ -64,7 +64,7 @@ async def test_hmip_home_cloud_connection_sensor(


async def test_hmip_acceleration_sensor(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipAccelerationSensor."""
entity_id = "binary_sensor.garagentor"
Expand Down Expand Up @@ -103,7 +103,7 @@ async def test_hmip_acceleration_sensor(


async def test_hmip_tilt_vibration_sensor(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipTiltVibrationSensor."""
entity_id = "binary_sensor.garage_neigungs_und_erschutterungssensor"
Expand Down Expand Up @@ -141,7 +141,7 @@ async def test_hmip_tilt_vibration_sensor(


async def test_hmip_contact_interface(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipContactInterface."""
entity_id = "binary_sensor.kontakt_schnittstelle_unterputz_1_fach"
Expand All @@ -166,7 +166,7 @@ async def test_hmip_contact_interface(


async def test_hmip_shutter_contact(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipShutterContact."""
entity_id = "binary_sensor.fenstergriffsensor"
Expand Down Expand Up @@ -208,7 +208,7 @@ async def test_hmip_shutter_contact(


async def test_hmip_shutter_contact_optical(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipShutterContact."""
entity_id = "binary_sensor.sitzplatzture"
Expand Down Expand Up @@ -240,7 +240,7 @@ async def test_hmip_shutter_contact_optical(


async def test_hmip_motion_detector(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipMotionDetector."""
entity_id = "binary_sensor.bewegungsmelder_fur_55er_rahmen_innen"
Expand All @@ -261,7 +261,7 @@ async def test_hmip_motion_detector(


async def test_hmip_presence_detector(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipPresenceDetector."""
entity_id = "binary_sensor.spi_1"
Expand All @@ -287,7 +287,7 @@ async def test_hmip_presence_detector(


async def test_hmip_pluggable_mains_failure_surveillance_sensor(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipPresenceDetector."""
entity_id = "binary_sensor.netzausfalluberwachung"
Expand All @@ -308,7 +308,7 @@ async def test_hmip_pluggable_mains_failure_surveillance_sensor(


async def test_hmip_smoke_detector(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipSmokeDetector."""
entity_id = "binary_sensor.rauchwarnmelder"
Expand Down Expand Up @@ -342,7 +342,7 @@ async def test_hmip_smoke_detector(


async def test_hmip_water_detector(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipWaterDetector."""
entity_id = "binary_sensor.wassersensor"
Expand Down Expand Up @@ -378,7 +378,9 @@ async def test_hmip_water_detector(
assert ha_state.state == STATE_OFF


async def test_hmip_storm_sensor(hass: HomeAssistant, default_mock_hap_factory) -> None:
async def test_hmip_storm_sensor(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipStormSensor."""
entity_id = "binary_sensor.weather_sensor_plus_storm"
entity_name = "Weather Sensor – plus Storm"
Expand All @@ -397,7 +399,9 @@ async def test_hmip_storm_sensor(hass: HomeAssistant, default_mock_hap_factory)
assert ha_state.state == STATE_ON


async def test_hmip_rain_sensor(hass: HomeAssistant, default_mock_hap_factory) -> None:
async def test_hmip_rain_sensor(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipRainSensor."""
entity_id = "binary_sensor.wettersensor_pro_raining"
entity_name = "Wettersensor - pro Raining"
Expand All @@ -417,7 +421,7 @@ async def test_hmip_rain_sensor(hass: HomeAssistant, default_mock_hap_factory) -


async def test_hmip_sunshine_sensor(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipSunshineSensor."""
entity_id = "binary_sensor.wettersensor_pro_sunshine"
Expand All @@ -439,7 +443,7 @@ async def test_hmip_sunshine_sensor(


async def test_hmip_battery_sensor(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipSunshineSensor."""
entity_id = "binary_sensor.wohnungsture_battery"
Expand All @@ -460,7 +464,7 @@ async def test_hmip_battery_sensor(


async def test_hmip_security_zone_sensor_group(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipSecurityZoneSensorGroup."""
entity_id = "binary_sensor.internal_securityzone"
Expand Down Expand Up @@ -497,7 +501,7 @@ async def test_hmip_security_zone_sensor_group(


async def test_hmip_security_sensor_group(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipSecuritySensorGroup."""
entity_id = "binary_sensor.buro_sensors"
Expand Down Expand Up @@ -571,7 +575,7 @@ async def test_hmip_security_sensor_group(


async def test_hmip_multi_contact_interface(
hass: HomeAssistant, default_mock_hap_factory
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
"""Test HomematicipMultiContactInterface."""
entity_id = "binary_sensor.wired_eingangsmodul_32_fach_channel5"
Expand Down
6 changes: 4 additions & 2 deletions tests/components/homematicip_cloud/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util

from .helper import get_and_check_entity_basics
from .helper import HomeFactory, get_and_check_entity_basics


async def test_hmip_garage_door_controller_button(
hass: HomeAssistant, freezer: FrozenDateTimeFactory, default_mock_hap_factory
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
default_mock_hap_factory: HomeFactory,
) -> None:
"""Test HomematicipGarageDoorControllerButton."""
entity_id = "button.garagentor"
Expand Down
Loading

0 comments on commit 197e65c

Please sign in to comment.