mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Add network MAC connection to Rabbit Air devices (#173684)
Co-authored-by: jasonjhofmann <16144532+jasonjhofmann@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
jasonjhofmann
Claude Opus 4.8
parent
cab0d015f6
commit
2c626fa8f0
@@ -6,7 +6,7 @@ from typing import Any
|
||||
from rabbitair import Model
|
||||
|
||||
from homeassistant.const import CONF_MAC
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
@@ -36,6 +36,7 @@ class RabbitAirBaseEntity(CoordinatorEntity[RabbitAirDataUpdateCoordinator]):
|
||||
self._attr_unique_id = entry.unique_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, entry.data[CONF_MAC])},
|
||||
connections={(CONNECTION_NETWORK_MAC, entry.data[CONF_MAC])},
|
||||
manufacturer="Rabbit Air",
|
||||
model=MODELS.get(coordinator.data.model),
|
||||
name=entry.title,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# serializer version: 1
|
||||
# name: test_device_registry
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'config_entries_subentries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'01:23:45:67:89:ab',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': '1.0.0.4',
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'rabbitair',
|
||||
'01:23:45:67:89:AB',
|
||||
),
|
||||
}),
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Rabbit Air',
|
||||
'model': 'A3',
|
||||
'model_id': None,
|
||||
'name': 'Rabbit Air',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'sw_version': '2.3.17',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,73 @@
|
||||
"""Test Rabbit Air integration setup."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from rabbitair import Mode, Model, Speed
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.rabbitair.const import DOMAIN
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_MAC
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
TEST_HOST = "1.1.1.1"
|
||||
TEST_TOKEN = "0123456789abcdef0123456789abcdef"
|
||||
TEST_MAC = "01:23:45:67:89:AB"
|
||||
TEST_FIRMWARE = "2.3.17"
|
||||
TEST_HARDWARE = "1.0.0.4"
|
||||
TEST_TITLE = "Rabbit Air"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def use_mocked_zeroconf(mock_async_zeroconf: MagicMock) -> None:
|
||||
"""Mock zeroconf in all tests."""
|
||||
|
||||
|
||||
def get_mock_state() -> Mock:
|
||||
"""Return a mock device state instance."""
|
||||
mock_state = Mock()
|
||||
mock_state.model = Model.A3
|
||||
mock_state.main_firmware = TEST_HARDWARE
|
||||
mock_state.power = True
|
||||
mock_state.mode = Mode.Auto
|
||||
mock_state.speed = Speed.Low
|
||||
mock_state.wifi_firmware = TEST_FIRMWARE
|
||||
return mock_state
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rabbitair_connect() -> Generator[None]:
|
||||
"""Mock connection."""
|
||||
with patch("rabbitair.UdpClient.get_state", return_value=get_mock_state()):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rabbitair_connect")
|
||||
async def test_device_registry(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the device registry entry, including the network MAC connection."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title=TEST_TITLE,
|
||||
unique_id=format_mac(TEST_MAC),
|
||||
data={
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_ACCESS_TOKEN: TEST_TOKEN,
|
||||
CONF_MAC: TEST_MAC,
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_entry = device_registry.async_get_device(identifiers={(DOMAIN, TEST_MAC)})
|
||||
assert device_entry == snapshot
|
||||
Reference in New Issue
Block a user