Skip to content

Commit 3f12d5b

Browse files
committed
Fix incapacity to create switch entity when automatic entity add is disabled at bootstrap
1 parent 8eb89b9 commit 3f12d5b

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 0.6.1
44

5-
- Fix missing key when bootstrap conf and adding switch
5+
- Fix incapacity to create switch entity when automatic entity add is disabled at bootstrap
66

77
## 0.6.0
88

custom_components/rfplayer/__init__.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ async def async_send_command(call):
9696
event_id = "_".join(
9797
[
9898
call.data[CONF_PROTOCOL],
99-
call.data.get(CONF_DEVICE_ID) or call.data.get(
100-
CONF_DEVICE_ADDRESS),
99+
call.data.get(CONF_DEVICE_ID) or call.data.get(CONF_DEVICE_ADDRESS),
101100
]
102101
)
103102
device = {
@@ -138,8 +137,7 @@ def event_callback(event):
138137
if entity_id:
139138
# Propagate event to every entity matching the device id
140139
_LOGGER.debug("passing event to %s", entity_id)
141-
async_dispatcher_send(
142-
hass, SIGNAL_HANDLE_EVENT.format(entity_id), event)
140+
async_dispatcher_send(hass, SIGNAL_HANDLE_EVENT.format(entity_id), event)
143141
else:
144142
# If device is not yet known, register with platform (if loaded)
145143
if event_type in hass.data[DOMAIN][DATA_DEVICE_REGISTER]:
@@ -213,9 +211,7 @@ async def connect():
213211
EVENT_KEY_COMMAND: defaultdict(list),
214212
EVENT_KEY_SENSOR: defaultdict(list),
215213
},
216-
DATA_DEVICE_REGISTER: {
217-
EVENT_KEY_COMMAND: {}
218-
},
214+
DATA_DEVICE_REGISTER: {},
219215
}
220216

221217
if options.get(CONF_AUTOMATIC_ADD, config[CONF_AUTOMATIC_ADD]) is True:
@@ -294,8 +290,7 @@ def handle_event_callback(self, event):
294290
if identify_event_type(event) == EVENT_KEY_COMMAND:
295291
self.hass.bus.async_fire(
296292
EVENT_BUTTON_PRESSED,
297-
{ATTR_ENTITY_ID: self.entity_id,
298-
ATTR_STATE: event[EVENT_KEY_COMMAND]},
293+
{ATTR_ENTITY_ID: self.entity_id, ATTR_STATE: event[EVENT_KEY_COMMAND]},
299294
)
300295
_LOGGER.debug(
301296
"Fired bus event for %s: %s", self.entity_id, event[EVENT_KEY_COMMAND]
@@ -361,10 +356,9 @@ async def async_added_to_hass(self):
361356
async def async_will_remove_from_hass(self):
362357
"""Clean when entity removed."""
363358
await super().async_will_remove_from_hass()
364-
device_registry = dr.async_get(hass)
359+
device_registry = dr.async_get(self.hass)
365360
device = device_registry.async_get_device(
366-
(DOMAIN, self.hass.data[DOMAIN]
367-
[CONF_DEVICE] + "_" + self._attr_unique_id)
361+
(DOMAIN, self.hass.data[DOMAIN][CONF_DEVICE] + "_" + self._attr_unique_id)
368362
)
369363
if device:
370364
device_registry.async_remove_device(device)

custom_components/rfplayer/number.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from homeassistant.core import callback
66
from homeassistant.helpers.entity import EntityCategory
77

8-
from . import EVENT_KEY_COMMAND, RfplayerDevice
9-
from .const import DATA_ENTITY_LOOKUP, DOMAIN, EVENT_KEY_ID, RFPLAYER_PROTOCOL
8+
from . import RfplayerDevice
9+
from .const import DOMAIN, RFPLAYER_PROTOCOL
1010

1111
_LOGGER = logging.getLogger(__name__)
1212

custom_components/rfplayer/switch.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from .const import (
1010
COMMAND_OFF,
1111
COMMAND_ON,
12-
CONF_AUTOMATIC_ADD,
1312
CONF_DEVICE_ADDRESS,
1413
DATA_ENTITY_LOOKUP,
1514
DOMAIN,
@@ -41,8 +40,7 @@ async def add_new_device(device_info):
4140
if EVENT_KEY_COMMAND in device_info:
4241
await add_new_device(device_info)
4342

44-
if options.get(CONF_AUTOMATIC_ADD, config[CONF_AUTOMATIC_ADD]):
45-
hass.data[DOMAIN][DATA_DEVICE_REGISTER][EVENT_KEY_COMMAND] = add_new_device
43+
hass.data[DOMAIN][DATA_DEVICE_REGISTER][EVENT_KEY_COMMAND] = add_new_device
4644

4745

4846
class RfplayerSwitch(RfplayerDevice, SwitchEntity):

0 commit comments

Comments
 (0)