mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Improvements for bluetooth device for lamarzocco (#131875)
This commit is contained in:
parent
bd29aaffb8
commit
6c6980a550
@ -6,8 +6,12 @@ from dataclasses import dataclass
|
||||
from pylamarzocco.const import FirmwareType
|
||||
from pylamarzocco.lm_machine import LaMarzoccoMachine
|
||||
|
||||
from homeassistant.const import CONF_ADDRESS
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_MAC
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_BLUETOOTH,
|
||||
CONNECTION_NETWORK_MAC,
|
||||
DeviceInfo,
|
||||
)
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
@ -48,17 +52,17 @@ class LaMarzoccoBaseEntity(
|
||||
serial_number=device.serial_number,
|
||||
sw_version=device.firmware[FirmwareType.MACHINE].current_version,
|
||||
)
|
||||
connections: set[tuple[str, str]] = set()
|
||||
if coordinator.config_entry.data.get(CONF_ADDRESS):
|
||||
self._attr_device_info.update(
|
||||
DeviceInfo(
|
||||
connections={
|
||||
(
|
||||
CONNECTION_NETWORK_MAC,
|
||||
coordinator.config_entry.data[CONF_ADDRESS],
|
||||
)
|
||||
}
|
||||
)
|
||||
connections.add(
|
||||
(CONNECTION_NETWORK_MAC, coordinator.config_entry.data[CONF_ADDRESS])
|
||||
)
|
||||
if coordinator.config_entry.data.get(CONF_MAC):
|
||||
connections.add(
|
||||
(CONNECTION_BLUETOOTH, coordinator.config_entry.data[CONF_MAC])
|
||||
)
|
||||
if connections:
|
||||
self._attr_device_info.update(DeviceInfo(connections=connections))
|
||||
|
||||
|
||||
class LaMarzoccoEntity(LaMarzoccoBaseEntity):
|
||||
|
41
tests/components/lamarzocco/snapshots/test_init.ambr
Normal file
41
tests/components/lamarzocco/snapshots/test_init.ambr
Normal file
@ -0,0 +1,41 @@
|
||||
# serializer version: 1
|
||||
# name: test_device
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
tuple(
|
||||
'bluetooth',
|
||||
'aa:bb:cc:dd:ee:ff',
|
||||
),
|
||||
tuple(
|
||||
'mac',
|
||||
'00:00:00:00:00:00',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'lamarzocco',
|
||||
'GS012345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'La Marzocco',
|
||||
'model': <MachineModel.GS3_AV: 'GS3 AV'>,
|
||||
'model_id': <MachineModel.GS3_AV: 'GS3 AV'>,
|
||||
'name': 'GS012345',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': 'GS012345',
|
||||
'suggested_area': None,
|
||||
'sw_version': '1.40',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
@ -91,42 +91,6 @@
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_device
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'00:00:00:00:00:00',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'lamarzocco',
|
||||
'GS012345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'La Marzocco',
|
||||
'model': <MachineModel.GS3_AV: 'GS3 AV'>,
|
||||
'model_id': <MachineModel.GS3_AV: 'GS3 AV'>,
|
||||
'name': 'GS012345',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': 'GS012345',
|
||||
'suggested_area': None,
|
||||
'sw_version': '1.40',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_switches[-set_power-kwargs0]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
|
@ -381,6 +381,26 @@ async def test_bluetooth_discovery(
|
||||
}
|
||||
|
||||
|
||||
async def test_bluetooth_discovery_already_configured(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_setup_entry: Generator[AsyncMock],
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test bluetooth discovery."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
service_info = get_bluetooth_service_info(
|
||||
mock_lamarzocco.model, mock_lamarzocco.serial_number
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_BLUETOOTH}, data=service_info
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_bluetooth_discovery_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
|
@ -5,6 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from pylamarzocco.const import FirmwareType
|
||||
from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
from websockets.protocol import State
|
||||
|
||||
from homeassistant.components.lamarzocco.config_flow import CONF_MACHINE
|
||||
@ -19,7 +20,11 @@ from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
entity_registry as er,
|
||||
issue_registry as ir,
|
||||
)
|
||||
|
||||
from . import USER_INPUT, async_init_integration, get_bluetooth_service_info
|
||||
|
||||
@ -220,3 +225,32 @@ async def test_gateway_version_issue(
|
||||
issue_registry = ir.async_get(hass)
|
||||
issue = issue_registry.async_get_issue(DOMAIN, "unsupported_gateway_firmware")
|
||||
assert (issue is not None) == issue_exists
|
||||
|
||||
|
||||
async def test_device(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the device."""
|
||||
|
||||
await async_init_integration(hass, mock_config_entry)
|
||||
|
||||
hass.config_entries.async_update_entry(
|
||||
mock_config_entry,
|
||||
data={**mock_config_entry.data, CONF_MAC: "aa:bb:cc:dd:ee:ff"},
|
||||
)
|
||||
|
||||
state = hass.states.get(f"switch.{mock_lamarzocco.serial_number}")
|
||||
assert state
|
||||
|
||||
entry = entity_registry.async_get(state.entity_id)
|
||||
assert entry
|
||||
assert entry.device_id
|
||||
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device
|
||||
assert device == snapshot
|
||||
|
@ -15,7 +15,7 @@ from homeassistant.components.switch import (
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import WAKE_UP_SLEEP_ENTRY_IDS, async_init_integration
|
||||
|
||||
@ -88,30 +88,6 @@ async def test_switches(
|
||||
control_fn.assert_called_with(enabled=True, **kwargs)
|
||||
|
||||
|
||||
async def test_device(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the device for one switch."""
|
||||
|
||||
await async_init_integration(hass, mock_config_entry)
|
||||
|
||||
state = hass.states.get(f"switch.{mock_lamarzocco.serial_number}")
|
||||
assert state
|
||||
|
||||
entry = entity_registry.async_get(state.entity_id)
|
||||
assert entry
|
||||
assert entry.device_id
|
||||
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device
|
||||
assert device == snapshot
|
||||
|
||||
|
||||
async def test_auto_on_off_switches(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
|
Loading…
x
Reference in New Issue
Block a user