mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fix updates of Rssi for control devices in rfxtrx (#38131)
* Change entity to entity_info * Fix bug in RSSI for Control devices
This commit is contained in:
parent
eb1970c015
commit
0e0f61764a
@ -48,7 +48,7 @@ async def async_setup_entry(
|
||||
def supported(event):
|
||||
return isinstance(event, rfxtrxmod.ControlEvent)
|
||||
|
||||
for packet_id, entity in discovery_info[CONF_DEVICES].items():
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
@ -56,7 +56,9 @@ async def async_setup_entry(
|
||||
if not supported(event):
|
||||
continue
|
||||
|
||||
device_id = get_device_id(event.device, data_bits=entity.get(CONF_DATA_BITS))
|
||||
device_id = get_device_id(
|
||||
event.device, data_bits=entity_info.get(CONF_DATA_BITS)
|
||||
)
|
||||
if device_id in device_ids:
|
||||
continue
|
||||
device_ids.add(device_id)
|
||||
@ -68,11 +70,11 @@ async def async_setup_entry(
|
||||
device = RfxtrxBinarySensor(
|
||||
event.device,
|
||||
device_id,
|
||||
entity.get(CONF_DEVICE_CLASS),
|
||||
entity.get(CONF_OFF_DELAY),
|
||||
entity.get(CONF_DATA_BITS),
|
||||
entity.get(CONF_COMMAND_ON),
|
||||
entity.get(CONF_COMMAND_OFF),
|
||||
entity_info.get(CONF_DEVICE_CLASS),
|
||||
entity_info.get(CONF_OFF_DELAY),
|
||||
entity_info.get(CONF_DATA_BITS),
|
||||
entity_info.get(CONF_COMMAND_ON),
|
||||
entity_info.get(CONF_COMMAND_OFF),
|
||||
)
|
||||
sensors.append(device)
|
||||
|
||||
|
@ -65,7 +65,7 @@ async def async_setup_entry(
|
||||
return isinstance(event, (ControlEvent, SensorEvent))
|
||||
|
||||
entities = []
|
||||
for packet_id, entity in discovery_info[CONF_DEVICES].items():
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
@ -73,7 +73,9 @@ async def async_setup_entry(
|
||||
if not supported(event):
|
||||
continue
|
||||
|
||||
device_id = get_device_id(event.device, data_bits=entity.get(CONF_DATA_BITS))
|
||||
device_id = get_device_id(
|
||||
event.device, data_bits=entity_info.get(CONF_DATA_BITS)
|
||||
)
|
||||
for data_type in set(event.values) & set(DATA_TYPES):
|
||||
data_id = (*device_id, data_type)
|
||||
if data_id in data_ids:
|
||||
@ -169,9 +171,6 @@ class RfxtrxSensor(RfxtrxEntity):
|
||||
@callback
|
||||
def _handle_event(self, event, device_id):
|
||||
"""Check if event applies to me and update."""
|
||||
if not isinstance(event, SensorEvent):
|
||||
return
|
||||
|
||||
if device_id != self._device_id:
|
||||
return
|
||||
|
||||
|
@ -290,3 +290,60 @@ async def test_update_of_sensors(hass, rfxtrx):
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_humidity")
|
||||
assert state
|
||||
assert state.state == "15"
|
||||
|
||||
|
||||
async def test_rssi_sensor(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0913000022670e013b70": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
"0b1100cd0213c7f230010f71": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
state = hass.states.get("sensor.pt2262_22670e_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "PT2262 22670e Rssi numeric"
|
||||
assert state.attributes.get("unit_of_measurement") == "dBm"
|
||||
|
||||
state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "AC 213c7f2:48 Rssi numeric"
|
||||
assert state.attributes.get("unit_of_measurement") == "dBm"
|
||||
|
||||
await rfxtrx.signal("0913000022670e013b70")
|
||||
await rfxtrx.signal("0b1100cd0213c7f230010f71")
|
||||
|
||||
state = hass.states.get("sensor.pt2262_22670e_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-64"
|
||||
|
||||
state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-64"
|
||||
|
||||
await rfxtrx.signal("0913000022670e013b60")
|
||||
await rfxtrx.signal("0b1100cd0213c7f230010f61")
|
||||
|
||||
state = hass.states.get("sensor.pt2262_22670e_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-72"
|
||||
|
||||
state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-72"
|
||||
|
Loading…
x
Reference in New Issue
Block a user