Fix missed case for device tuple fallback in rfxtrx (#93575)
* rfxtrx: add missed case for device tuple fallback Previously the code was prepared for a backward compatible migration of tuples, where both styles of identifiers might exist in device registry at the same time. This place was sadly missed * No need to raise special, we can assert instead * Add some basic tests
This commit is contained in:
parent
e1ef027461
commit
617ff24b9b
3 changed files with 23 additions and 2 deletions
|
@ -6,6 +6,8 @@ from RFXtrx import RFXtrxDevice, get_device
|
|||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from . import get_device_tuple_from_identifiers
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_device_object(hass: HomeAssistant, device_id: str) -> RFXtrxDevice:
|
||||
|
@ -15,7 +17,9 @@ def async_get_device_object(hass: HomeAssistant, device_id: str) -> RFXtrxDevice
|
|||
if registry_device is None:
|
||||
raise ValueError(f"Device {device_id} not found")
|
||||
|
||||
device_tuple = list(list(registry_device.identifiers)[0])
|
||||
device_tuple = get_device_tuple_from_identifiers(registry_device.identifiers)
|
||||
assert device_tuple
|
||||
|
||||
return get_device(
|
||||
int(device_tuple[1], 16), int(device_tuple[2], 16), device_tuple[3]
|
||||
int(device_tuple[0], 16), int(device_tuple[1], 16), device_tuple[2]
|
||||
)
|
||||
|
|
|
@ -89,6 +89,14 @@ async def test_get_actions(
|
|||
device_entry = device_registry.async_get_device(device.device_identifiers, set())
|
||||
assert device_entry
|
||||
|
||||
# Add alternate identifiers, to make sure we can handle future formats
|
||||
identifiers: list[str] = list(*device_entry.identifiers)
|
||||
device_registry.async_update_device(
|
||||
device_entry.id, merge_identifiers={(identifiers[0], "_".join(identifiers[1:]))}
|
||||
)
|
||||
device_entry = device_registry.async_get_device(device.device_identifiers, set())
|
||||
assert device_entry
|
||||
|
||||
actions = await async_get_device_automations(
|
||||
hass, DeviceAutomationType.ACTION, device_entry.id
|
||||
)
|
||||
|
|
|
@ -88,6 +88,15 @@ async def test_get_triggers(
|
|||
await setup_entry(hass, {event.code: {}})
|
||||
|
||||
device_entry = device_registry.async_get_device(event.device_identifiers, set())
|
||||
assert device_entry
|
||||
|
||||
# Add alternate identifiers, to make sure we can handle future formats
|
||||
identifiers: list[str] = list(*event.device_identifiers)
|
||||
device_registry.async_update_device(
|
||||
device_entry.id, merge_identifiers={(identifiers[0], "_".join(identifiers[1:]))}
|
||||
)
|
||||
device_entry = device_registry.async_get_device(event.device_identifiers, set())
|
||||
assert device_entry
|
||||
|
||||
expected_triggers = [
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue