Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aohzan committed Mar 21, 2024
1 parent e642a45 commit b2c6785
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions custom_components/rfplayer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Rfplayer devices."""

from asyncio import timeout
from collections import defaultdict
import copy
Expand Down Expand Up @@ -77,11 +78,21 @@ def identify_event_type(event):

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up GCE RFPlayer from a config entry."""
hass.data.setdefault(DOMAIN, {})

config = entry.data
options = entry.options

hass.data.setdefault(
DOMAIN,
{
CONF_DEVICE: config[CONF_DEVICE],
DATA_ENTITY_LOOKUP: {
EVENT_KEY_COMMAND: defaultdict(list),
EVENT_KEY_SENSOR: defaultdict(list),
},
DATA_DEVICE_REGISTER: {},
},
)

async def async_send_command(call):
"""Send Rfplayer command."""
_LOGGER.debug("Rfplayer send command for %s", str(call.data))
Expand Down Expand Up @@ -181,7 +192,7 @@ async def connect():
)

try:
with timeout(CONNECTION_TIMEOUT):
async with timeout(CONNECTION_TIMEOUT):
transport, protocol = await connection

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

hass.data[DOMAIN] = {
RFPLAYER_PROTOCOL: protocol,
CONF_DEVICE: config[CONF_DEVICE],
DATA_ENTITY_LOOKUP: {
EVENT_KEY_COMMAND: defaultdict(list),
EVENT_KEY_SENSOR: defaultdict(list),
},
DATA_DEVICE_REGISTER: {},
}
hass.data[DOMAIN][RFPLAYER_PROTOCOL] = (protocol,)

if options.get(CONF_AUTOMATIC_ADD, config[CONF_AUTOMATIC_ADD]) is True:
for device_type in "sensor", "command":
Expand Down Expand Up @@ -254,7 +257,7 @@ def __init__(
self._event = None
self._attr_assumed_state = True
self._attr_unique_id = "_".join(
[self._protocol, self._device_address or self._device_id]
[self._protocol, self._device_address or str(self._device_id)]
)
if name:
self._attr_name = name
Expand Down
2 changes: 1 addition & 1 deletion custom_components/rfplayer/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RfplayerJammingNumber(RfplayerDevice, RestoreNumber):
def __init__(self) -> None:
"""Init the number rfplayer entity."""
self._state: int | None = None
super().__init__("JAMMING")
super().__init__(name="JAMMING", device_id=0)

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

0 comments on commit b2c6785

Please sign in to comment.