Set friendly name for PT2262 sensors to masked name (#135988)

pull/136120/head
Joakim Plate 2025-01-19 21:07:05 +01:00 committed by GitHub
parent 2900baac04
commit a69786f64f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 28 deletions

View File

@ -46,7 +46,7 @@ class RfxtrxEntity(RestoreEntity):
self._attr_device_info = DeviceInfo(
identifiers=_get_identifiers_from_device_tuple(device_id),
model=device.type_string,
name=f"{device.type_string} {device.id_string}",
name=f"{device.type_string} {device_id.id_string}",
)
self._attr_unique_id = "_".join(x for x in device_id)
self._device = device
@ -54,7 +54,7 @@ class RfxtrxEntity(RestoreEntity):
self._device_id = device_id
# If id_string is 213c7f2:1, the group_id is 213c7f2, and the device will respond to
# group events regardless of their group indices.
(self._group_id, _, _) = cast(str, device.id_string).partition(":")
(self._group_id, _, _) = device_id.id_string.partition(":")
async def async_added_to_hass(self) -> None:
"""Restore RFXtrx device state (ON/OFF)."""

View File

@ -58,17 +58,17 @@ async def test_one_pt2262(hass: HomeAssistant, rfxtrx) -> None:
await hass.async_block_till_done()
await hass.async_start()
state = hass.states.get("binary_sensor.pt2262_22670e")
state = hass.states.get("binary_sensor.pt2262_226700")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
assert state.attributes.get("friendly_name") == "PT2262 226700"
await rfxtrx.signal("0913000022670e013970")
state = hass.states.get("binary_sensor.pt2262_22670e")
state = hass.states.get("binary_sensor.pt2262_226700")
assert state.state == "on"
await rfxtrx.signal("09130000226707013d70")
state = hass.states.get("binary_sensor.pt2262_22670e")
state = hass.states.get("binary_sensor.pt2262_226700")
assert state.state == "off"
@ -85,10 +85,10 @@ async def test_pt2262_unconfigured(hass: HomeAssistant, rfxtrx) -> None:
await hass.async_block_till_done()
await hass.async_start()
state = hass.states.get("binary_sensor.pt2262_22670e")
state = hass.states.get("binary_sensor.pt2262_226707")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
assert state.attributes.get("friendly_name") == "PT2262 226707"
state = hass.states.get("binary_sensor.pt2262_226707")
assert state
@ -318,7 +318,7 @@ async def test_pt2262_duplicate_id(hass: HomeAssistant, rfxtrx) -> None:
await hass.async_block_till_done()
await hass.async_start()
state = hass.states.get("binary_sensor.pt2262_22670e")
state = hass.states.get("binary_sensor.pt2262_226700")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
assert state.attributes.get("friendly_name") == "PT2262 226700"

View File

@ -756,10 +756,10 @@ async def test_options_add_and_configure_device(
assert entry.data["devices"]["0913000022670e013970"]
assert entry.data["devices"]["0913000022670e013970"]["off_delay"] == 9
state = hass.states.get("binary_sensor.pt2262_22670e")
state = hass.states.get("binary_sensor.pt2262_226700")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
assert state.attributes.get("friendly_name") == "PT2262 226700"
device_entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)

View File

@ -330,10 +330,10 @@ async def test_rssi_sensor(hass: HomeAssistant, rfxtrx) -> None:
await hass.async_block_till_done()
await hass.async_start()
state = hass.states.get("sensor.pt2262_22670e_signal_strength")
state = hass.states.get("sensor.pt2262_226700_signal_strength")
assert state
assert state.state == "unknown"
assert state.attributes.get("friendly_name") == "PT2262 22670e Signal strength"
assert state.attributes.get("friendly_name") == "PT2262 226700 Signal strength"
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
@ -351,7 +351,7 @@ async def test_rssi_sensor(hass: HomeAssistant, rfxtrx) -> None:
await rfxtrx.signal("0913000022670e013b70")
await rfxtrx.signal("0b1100cd0213c7f230010f71")
state = hass.states.get("sensor.pt2262_22670e_signal_strength")
state = hass.states.get("sensor.pt2262_226700_signal_strength")
assert state
assert state.state == "-64"
@ -362,7 +362,7 @@ async def test_rssi_sensor(hass: HomeAssistant, rfxtrx) -> None:
await rfxtrx.signal("0913000022670e013b60")
await rfxtrx.signal("0b1100cd0213c7f230010f61")
state = hass.states.get("sensor.pt2262_22670e_signal_strength")
state = hass.states.get("sensor.pt2262_226700_signal_strength")
assert state
assert state.state == "-72"

View File

@ -70,23 +70,23 @@ async def test_one_pt2262_switch(hass: HomeAssistant, rfxtrx) -> None:
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("switch.pt2262_22670e")
state = hass.states.get("switch.pt2262_226700")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
assert state.attributes.get("friendly_name") == "PT2262 226700"
await hass.services.async_call(
"switch", "turn_on", {"entity_id": "switch.pt2262_22670e"}, blocking=True
"switch", "turn_on", {"entity_id": "switch.pt2262_226700"}, blocking=True
)
state = hass.states.get("switch.pt2262_22670e")
state = hass.states.get("switch.pt2262_226700")
assert state.state == "on"
await hass.services.async_call(
"switch", "turn_off", {"entity_id": "switch.pt2262_22670e"}, blocking=True
"switch", "turn_off", {"entity_id": "switch.pt2262_226700"}, blocking=True
)
state = hass.states.get("switch.pt2262_22670e")
state = hass.states.get("switch.pt2262_226700")
assert state.state == "off"
assert rfxtrx.transport.send.mock_calls == [
@ -220,26 +220,26 @@ async def test_pt2262_switch_events(hass: HomeAssistant, rfxtrx) -> None:
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("switch.pt2262_22670e")
state = hass.states.get("switch.pt2262_226700")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes.get("friendly_name") == "PT2262 22670e"
assert state.attributes.get("friendly_name") == "PT2262 226700"
# "Command: 0xE"
await rfxtrx.signal("0913000022670e013970")
assert hass.states.get("switch.pt2262_22670e").state == "on"
assert hass.states.get("switch.pt2262_226700").state == "on"
# "Command: 0x0"
await rfxtrx.signal("09130000226700013970")
assert hass.states.get("switch.pt2262_22670e").state == "on"
assert hass.states.get("switch.pt2262_226700").state == "on"
# "Command: 0x7"
await rfxtrx.signal("09130000226707013d70")
assert hass.states.get("switch.pt2262_22670e").state == "off"
assert hass.states.get("switch.pt2262_226700").state == "off"
# "Command: 0x1"
await rfxtrx.signal("09130000226701013d70")
assert hass.states.get("switch.pt2262_22670e").state == "off"
assert hass.states.get("switch.pt2262_226700").state == "off"
async def test_discover_switch(hass: HomeAssistant, rfxtrx_automatic) -> None: