mirror of
https://github.com/home-assistant/core.git
synced 2026-10-19 12:56:53 -04:00
Bump pytradfri to 14.0.0 (#182250)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Common tools used for the Tradfri test suite."""
|
||||
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
@@ -62,7 +61,7 @@ class CommandStore:
|
||||
assert observe_command
|
||||
|
||||
device_path = "/".join(str(v) for v in device.path)
|
||||
device_state = deepcopy(device.raw)
|
||||
device_state = device.raw.dict(by_alias=True)
|
||||
|
||||
# Create a default observed state based on the sent commands.
|
||||
for command in self.sent_commands:
|
||||
|
||||
@@ -7,13 +7,12 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from pytradfri.command import Command
|
||||
from pytradfri.const import ATTR_FIRMWARE_VERSION, ATTR_GATEWAY_ID
|
||||
from pytradfri.device import Device
|
||||
from pytradfri.gateway import Gateway
|
||||
|
||||
from homeassistant.components.tradfri.const import DOMAIN
|
||||
|
||||
from . import GATEWAY_ID, TRADFRI_PATH
|
||||
from . import TRADFRI_PATH
|
||||
from .common import CommandStore
|
||||
|
||||
from tests.common import load_fixture
|
||||
@@ -28,12 +27,12 @@ def mock_entry_setup() -> Generator[AsyncMock]:
|
||||
|
||||
|
||||
@pytest.fixture(name="mock_gateway", autouse=True)
|
||||
def mock_gateway_fixture(command_store: CommandStore) -> Gateway:
|
||||
def mock_gateway_fixture(command_store: CommandStore, gateway_response: str) -> Gateway:
|
||||
"""Mock a Tradfri gateway."""
|
||||
gateway = Gateway()
|
||||
command_store.register_response(
|
||||
gateway.get_gateway_info(),
|
||||
{ATTR_GATEWAY_ID: GATEWAY_ID, ATTR_FIRMWARE_VERSION: "1.2.1234"},
|
||||
json.loads(gateway_response),
|
||||
)
|
||||
command_store.register_response(
|
||||
gateway.get_devices(),
|
||||
@@ -90,10 +89,16 @@ def device(
|
||||
"""Return a device."""
|
||||
device_response: dict[str, Any] = json.loads(request.getfixturevalue(request.param))
|
||||
device = Device(device_response)
|
||||
command_store.register_device(mock_gateway, device.raw)
|
||||
command_store.register_device(mock_gateway, device_response)
|
||||
return device
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def gateway_response() -> str:
|
||||
"""Return a gateway response."""
|
||||
return load_fixture("gateway.json", DOMAIN)
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def air_purifier() -> str:
|
||||
"""Return an air purifier response."""
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"9023": "xyz.pool.ntp.pool",
|
||||
"9029": "1.2.1234",
|
||||
"9054": 0,
|
||||
"9055": 0,
|
||||
"9059": 1509788799,
|
||||
"9060": "2017-11-04T09:46:39.046784Z",
|
||||
"9061": 0,
|
||||
"9062": 0,
|
||||
"9066": 5,
|
||||
"9069": 1509474847,
|
||||
"9071": 1,
|
||||
"9072": 0,
|
||||
"9073": 0,
|
||||
"9074": 0,
|
||||
"9075": 0,
|
||||
"9076": 0,
|
||||
"9077": 0,
|
||||
"9078": 0,
|
||||
"9079": 0,
|
||||
"9080": 0,
|
||||
"9081": "mock-gateway-id",
|
||||
"9082": true,
|
||||
"9083": "123-45-67",
|
||||
"9092": 0,
|
||||
"9093": 0,
|
||||
"9103": "blablablabla12.iot.eu-central-1.amazonaws.com",
|
||||
"9105": 0,
|
||||
"9106": 0,
|
||||
"9107": 0,
|
||||
"9118": 0,
|
||||
"9200": "abc12345-a123-b345-c567-123abc123456",
|
||||
"9201": 1,
|
||||
"9202": 1234567890,
|
||||
"9204": 1,
|
||||
"9208": 1234567890,
|
||||
"9209": 1234567890,
|
||||
"9211": 0,
|
||||
"9232": 1234567,
|
||||
"9234": 1,
|
||||
"9235": "SE",
|
||||
"9236": 3600,
|
||||
"9266": 2
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Tests for Tradfri setup."""
|
||||
|
||||
import json
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from pytradfri.const import ATTR_FIRMWARE_VERSION, ATTR_GATEWAY_ID
|
||||
from pytradfri.const import ATTR_GATEWAY_ID
|
||||
from pytradfri.gateway import Gateway
|
||||
|
||||
from homeassistant.components import tradfri
|
||||
@@ -104,6 +105,7 @@ async def test_migrate_config_entry_and_identifiers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
command_store: CommandStore,
|
||||
gateway_response: str,
|
||||
) -> None:
|
||||
"""Test migration of device registry identifiers to the unique format.
|
||||
|
||||
@@ -120,7 +122,7 @@ async def test_migrate_config_entry_and_identifiers(
|
||||
},
|
||||
)
|
||||
|
||||
gateway1 = mock_gateway_fixture(command_store, GATEWAY_ID1)
|
||||
gateway1 = mock_gateway_fixture(command_store, GATEWAY_ID1, gateway_response)
|
||||
command_store.register_device(
|
||||
gateway1, await async_load_json_object_fixture(hass, "bulb_w.json", DOMAIN)
|
||||
)
|
||||
@@ -226,12 +228,16 @@ async def test_migrate_config_entry_and_identifiers(
|
||||
assert config_entry3.version == 1
|
||||
|
||||
|
||||
def mock_gateway_fixture(command_store: CommandStore, gateway_id: str) -> Gateway:
|
||||
def mock_gateway_fixture(
|
||||
command_store: CommandStore, gateway_id: str, gateway_response: str
|
||||
) -> Gateway:
|
||||
"""Mock a Tradfri gateway."""
|
||||
gateway = Gateway()
|
||||
gateway_info_response = json.loads(gateway_response)
|
||||
gateway_info_response[ATTR_GATEWAY_ID] = gateway_id
|
||||
command_store.register_response(
|
||||
gateway.get_gateway_info(),
|
||||
{ATTR_GATEWAY_ID: gateway_id, ATTR_FIRMWARE_VERSION: "1.2.1234"},
|
||||
gateway_info_response,
|
||||
)
|
||||
command_store.register_response(
|
||||
gateway.get_devices(),
|
||||
|
||||
@@ -245,10 +245,16 @@ async def test_turn_on(
|
||||
state_attributes: dict[str, Any],
|
||||
) -> None:
|
||||
"""Test turning on a light."""
|
||||
# Make sure the light is off.
|
||||
device.raw[ATTR_LIGHT_CONTROL][0][ATTR_DEVICE_STATE] = 0
|
||||
await setup_integration(hass)
|
||||
|
||||
await command_store.trigger_observe_callback(
|
||||
hass, device, {ATTR_LIGHT_CONTROL: [{ATTR_DEVICE_STATE: 0}]}
|
||||
)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
|
||||
Reference in New Issue
Block a user