Skip to content

Commit 1379dd0

Browse files
committed
Fix options changes not reloading integration
1 parent 6aade0f commit 1379dd0

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Replace the jamming sensor by a binary_sensor and add events catching to it
1111
- Allow to specify manual path to USB device
1212
- Disallow multi instance of the integration
13+
- Fix options changes not reloading integration
1314

1415
## 0.6.1
1516

custom_components/rfplayer/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ async def connect():
228228

229229
hass.data[DOMAIN][RFPLAYER_PROTOCOL] = protocol
230230

231+
entry.add_update_listener(_async_update_listener)
232+
231233
if options.get(CONF_AUTOMATIC_ADD, config[CONF_AUTOMATIC_ADD]) is True:
232234
for device_type in "sensor", "command":
233235
hass.data[DOMAIN][DATA_DEVICE_REGISTER][device_type] = {}
@@ -248,6 +250,20 @@ async def connect():
248250
return True
249251

250252

253+
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
254+
"""Unload a config entry."""
255+
await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
256+
257+
hass.data.pop(DOMAIN)
258+
259+
return True
260+
261+
262+
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
263+
"""Handle options update."""
264+
await hass.config_entries.async_reload(entry.entry_id)
265+
266+
251267
# pylint: disable-next=too-many-instance-attributes
252268
class RfplayerDevice(RestoreEntity):
253269
"""Representation of a Rfplayer device.

custom_components/rfplayer/rflib/rfpparser.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ def packet_events(packet: PacketType) -> Generator[PacketType, None, None]:
230230
# packet["message"]
231231
# yield { "id": packet_id, "message": packet["message"] }
232232
# except KeyError:
233-
for sensor, value in events.items():
234-
log.debug("packet_events, sensor:%s,value:%s", sensor, value)
235-
unit = packet.get(sensor + "_unit", None)
233+
for paquet_type, value in events.items():
234+
log.debug("packet_events, sensor:%s,value:%s", paquet_type, value)
235+
unit = packet.get(paquet_type + "_unit", None)
236236
yield {
237-
"id": packet_id + PACKET_ID_SEP + field_abbrev[sensor],
238-
"sensor": sensor,
237+
"id": packet_id + PACKET_ID_SEP + field_abbrev[paquet_type],
238+
"sensor": paquet_type,
239239
"value": value,
240240
"unit": unit,
241241
}

0 commit comments

Comments
 (0)