mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Load homekit_controller test data using its json loader (#97534)
This commit is contained in:
parent
651d4134cf
commit
e7069d48be
@ -3,12 +3,12 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Any, Final
|
from typing import Any, Final
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
from aiohomekit.hkjson import loads as hkloads
|
||||||
from aiohomekit.model import (
|
from aiohomekit.model import (
|
||||||
Accessories,
|
Accessories,
|
||||||
AccessoriesState,
|
AccessoriesState,
|
||||||
@ -185,7 +185,7 @@ async def setup_accessories_from_file(hass, path):
|
|||||||
accessories_fixture = await hass.async_add_executor_job(
|
accessories_fixture = await hass.async_add_executor_job(
|
||||||
load_fixture, os.path.join("homekit_controller", path)
|
load_fixture, os.path.join("homekit_controller", path)
|
||||||
)
|
)
|
||||||
accessories_json = json.loads(accessories_fixture)
|
accessories_json = hkloads(accessories_fixture)
|
||||||
accessories = Accessories.from_list(accessories_json)
|
accessories = Accessories.from_list(accessories_json)
|
||||||
return accessories
|
return accessories
|
||||||
|
|
||||||
|
@ -20,7 +20,86 @@ from ..common import (
|
|||||||
async def test_connectsense_setup(hass: HomeAssistant) -> None:
|
async def test_connectsense_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test that the accessory can be correctly setup in HA."""
|
"""Test that the accessory can be correctly setup in HA."""
|
||||||
accessories = await setup_accessories_from_file(hass, "connectsense.json")
|
accessories = await setup_accessories_from_file(hass, "connectsense.json")
|
||||||
await setup_test_accessories(hass, accessories)
|
config_entry, pairing = await setup_test_accessories(hass, accessories)
|
||||||
|
|
||||||
|
await assert_devices_and_entities_created(
|
||||||
|
hass,
|
||||||
|
DeviceTestInfo(
|
||||||
|
unique_id=HUB_TEST_ACCESSORY_ID,
|
||||||
|
name="InWall Outlet-0394DE",
|
||||||
|
model="CS-IWO",
|
||||||
|
manufacturer="ConnectSense",
|
||||||
|
sw_version="1.0.0",
|
||||||
|
hw_version="",
|
||||||
|
serial_number="1020301376",
|
||||||
|
devices=[],
|
||||||
|
entities=[
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="sensor.inwall_outlet_0394de_current",
|
||||||
|
friendly_name="InWall Outlet-0394DE Current",
|
||||||
|
unique_id="00:00:00:00:00:00_1_13_18",
|
||||||
|
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||||
|
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||||
|
state="0.03",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="sensor.inwall_outlet_0394de_power",
|
||||||
|
friendly_name="InWall Outlet-0394DE Power",
|
||||||
|
unique_id="00:00:00:00:00:00_1_13_19",
|
||||||
|
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||||
|
unit_of_measurement=POWER_WATT,
|
||||||
|
state="0.8",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="sensor.inwall_outlet_0394de_energy_kwh",
|
||||||
|
friendly_name="InWall Outlet-0394DE Energy kWh",
|
||||||
|
unique_id="00:00:00:00:00:00_1_13_20",
|
||||||
|
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||||
|
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||||
|
state="379.69299",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="switch.inwall_outlet_0394de_outlet_a",
|
||||||
|
friendly_name="InWall Outlet-0394DE Outlet A",
|
||||||
|
unique_id="00:00:00:00:00:00_1_13",
|
||||||
|
state="on",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="sensor.inwall_outlet_0394de_current_2",
|
||||||
|
friendly_name="InWall Outlet-0394DE Current",
|
||||||
|
unique_id="00:00:00:00:00:00_1_25_30",
|
||||||
|
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||||
|
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||||
|
state="0.05",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="sensor.inwall_outlet_0394de_power_2",
|
||||||
|
friendly_name="InWall Outlet-0394DE Power",
|
||||||
|
unique_id="00:00:00:00:00:00_1_25_31",
|
||||||
|
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||||
|
unit_of_measurement=POWER_WATT,
|
||||||
|
state="0.8",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="sensor.inwall_outlet_0394de_energy_kwh_2",
|
||||||
|
friendly_name="InWall Outlet-0394DE Energy kWh",
|
||||||
|
unique_id="00:00:00:00:00:00_1_25_32",
|
||||||
|
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||||
|
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||||
|
state="175.85001",
|
||||||
|
),
|
||||||
|
EntityTestInfo(
|
||||||
|
entity_id="switch.inwall_outlet_0394de_outlet_b",
|
||||||
|
friendly_name="InWall Outlet-0394DE Outlet B",
|
||||||
|
unique_id="00:00:00:00:00:00_1_25",
|
||||||
|
state="on",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
await assert_devices_and_entities_created(
|
await assert_devices_and_entities_created(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user