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:
Joakim Plate 2023-05-29 19:59:11 +02:00 committed by GitHub
parent e1ef027461
commit 617ff24b9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View file

@ -6,6 +6,8 @@ from RFXtrx import RFXtrxDevice, get_device
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from . import get_device_tuple_from_identifiers
@callback @callback
def async_get_device_object(hass: HomeAssistant, device_id: str) -> RFXtrxDevice: 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: if registry_device is None:
raise ValueError(f"Device {device_id} not found") 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( 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]
) )

View file

@ -89,6 +89,14 @@ async def test_get_actions(
device_entry = device_registry.async_get_device(device.device_identifiers, set()) device_entry = device_registry.async_get_device(device.device_identifiers, set())
assert device_entry 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( actions = await async_get_device_automations(
hass, DeviceAutomationType.ACTION, device_entry.id hass, DeviceAutomationType.ACTION, device_entry.id
) )

View file

@ -88,6 +88,15 @@ async def test_get_triggers(
await setup_entry(hass, {event.code: {}}) await setup_entry(hass, {event.code: {}})
device_entry = device_registry.async_get_device(event.device_identifiers, set()) 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 = [ expected_triggers = [
{ {