Skip to content

Commit 8efe500

Browse files
committed
Apply persisted role to messages missing role
1 parent 6c44fcd commit 8efe500

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

custom_components/powersensor/PowersensorMessageDispatcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44

55
from homeassistant.core import HomeAssistant, callback
6+
from homeassistant.config_entries import ConfigEntry
67
from homeassistant.helpers.dispatcher import async_dispatcher_send, async_dispatcher_connect
78

89
from powersensor_local import PlugApi, VirtualHousehold
@@ -12,8 +13,9 @@
1213

1314
_LOGGER = logging.getLogger(__name__)
1415
class PowersensorMessageDispatcher:
15-
def __init__(self, hass: HomeAssistant, vhh: VirtualHousehold, debounce_timeout: float = 60):
16+
def __init__(self, hass: HomeAssistant, entry: ConfigEntry, vhh: VirtualHousehold, debounce_timeout: float = 60):
1617
self._hass = hass
18+
self._entry = entry
1719
self._vhh = vhh
1820
self.plugs = dict()
1921
self._known_plugs = set()
@@ -163,6 +165,8 @@ def cancel_any_pending_removal(self, mac, source):
163165
async def handle_message(self, event: str, message: dict):
164166
mac = message['mac']
165167
role = message.get('role', None)
168+
if role is None:
169+
role = self._entry.data.get('roles', {}).get(mac, None)
166170
self.cancel_any_pending_removal(mac, "new message received from plug")
167171

168172
if mac not in self.plugs.keys():

custom_components/powersensor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
5151
vhh = VirtualHousehold(entry.data['with_solar'])
5252

5353
# Set up message dispatcher
54-
dispatcher = PowersensorMessageDispatcher(hass, vhh)
54+
dispatcher = PowersensorMessageDispatcher(hass, entry, vhh)
5555
for mac, network_info in entry.data['devices'].items():
5656
await dispatcher.enqueue_plug_for_adding(network_info)
5757

0 commit comments

Comments
 (0)