Skip to content

Commit b2c6785

Browse files
committed
fixes
1 parent e642a45 commit b2c6785

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

custom_components/rfplayer/__init__.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Support for Rfplayer devices."""
2+
23
from asyncio import timeout
34
from collections import defaultdict
45
import copy
@@ -77,11 +78,21 @@ def identify_event_type(event):
7778

7879
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
7980
"""Set up GCE RFPlayer from a config entry."""
80-
hass.data.setdefault(DOMAIN, {})
81-
8281
config = entry.data
8382
options = entry.options
8483

84+
hass.data.setdefault(
85+
DOMAIN,
86+
{
87+
CONF_DEVICE: config[CONF_DEVICE],
88+
DATA_ENTITY_LOOKUP: {
89+
EVENT_KEY_COMMAND: defaultdict(list),
90+
EVENT_KEY_SENSOR: defaultdict(list),
91+
},
92+
DATA_DEVICE_REGISTER: {},
93+
},
94+
)
95+
8596
async def async_send_command(call):
8697
"""Send Rfplayer command."""
8798
_LOGGER.debug("Rfplayer send command for %s", str(call.data))
@@ -181,7 +192,7 @@ async def connect():
181192
)
182193

183194
try:
184-
with timeout(CONNECTION_TIMEOUT):
195+
async with timeout(CONNECTION_TIMEOUT):
185196
transport, protocol = await connection
186197

187198
except (TimeoutError, SerialException, OSError) as exc:
@@ -199,15 +210,7 @@ async def connect():
199210
# mark entities as available
200211
async_dispatcher_send(hass, SIGNAL_AVAILABILITY, True)
201212

202-
hass.data[DOMAIN] = {
203-
RFPLAYER_PROTOCOL: protocol,
204-
CONF_DEVICE: config[CONF_DEVICE],
205-
DATA_ENTITY_LOOKUP: {
206-
EVENT_KEY_COMMAND: defaultdict(list),
207-
EVENT_KEY_SENSOR: defaultdict(list),
208-
},
209-
DATA_DEVICE_REGISTER: {},
210-
}
213+
hass.data[DOMAIN][RFPLAYER_PROTOCOL] = (protocol,)
211214

212215
if options.get(CONF_AUTOMATIC_ADD, config[CONF_AUTOMATIC_ADD]) is True:
213216
for device_type in "sensor", "command":
@@ -254,7 +257,7 @@ def __init__(
254257
self._event = None
255258
self._attr_assumed_state = True
256259
self._attr_unique_id = "_".join(
257-
[self._protocol, self._device_address or self._device_id]
260+
[self._protocol, self._device_address or str(self._device_id)]
258261
)
259262
if name:
260263
self._attr_name = name

custom_components/rfplayer/number.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RfplayerJammingNumber(RfplayerDevice, RestoreNumber):
3030
def __init__(self) -> None:
3131
"""Init the number rfplayer entity."""
3232
self._state: int | None = None
33-
super().__init__("JAMMING")
33+
super().__init__(name="JAMMING", device_id=0)
3434

3535
async def async_added_to_hass(self) -> None:
3636
"""Restore RFPlayer device state."""

0 commit comments

Comments
 (0)