Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote node , exclude domains and entities #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions custom_components/remote_homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from homeassistant.core import callback, Context
import homeassistant.components.websocket_api.auth as api
from homeassistant.core import EventOrigin, split_entity_id
from homeassistant.helpers.device_registry import EVENT_DEVICE_REGISTRY_UPDATED, DeviceEntry
from homeassistant.helpers.entity_registry import RegistryEntry, EVENT_ENTITY_REGISTRY_UPDATED
from homeassistant.helpers.typing import HomeAssistantType, ConfigType
from homeassistant.const import (CONF_HOST, CONF_PORT, EVENT_CALL_SERVICE,
EVENT_HOMEASSISTANT_STOP,
Expand Down Expand Up @@ -261,7 +263,7 @@ async def _recv(self):
else:
callback = self._handlers.get(message['id'])
if callback is not None:
callback(message)
await callback(message)

await self._disconnected()

Expand Down Expand Up @@ -370,7 +372,7 @@ def state_changed(entity_id, state, attr):
self._entities.add(entity_id)
self._hass.states.async_set(entity_id, state, attr)

def fire_event(message):
async def fire_event(message):
"""Publish remove event on local instance."""
if message['type'] == 'result':
return
Expand Down Expand Up @@ -402,7 +404,7 @@ def fire_event(message):
origin=EventOrigin.remote
)

def got_states(message):
async def got_states(message):
"""Called when list of remote states is available."""
for entity in message['result']:
entity_id = entity['entity_id']
Expand All @@ -411,9 +413,47 @@ def got_states(message):

state_changed(entity_id, state, attributes)

#def device_registry_updated()

device_registry = await self._hass.helpers.device_registry.async_get_registry()

async def got_device_registry_list(message):
for entry in message['result']:
device_id = entry['id']
is_new = device_id in device_registry.devices

device_registry.devices[device_id] = DeviceEntry(is_new=is_new, **entry)
device_registry.async_schedule_save()

self._hass.bus.async_fire(
EVENT_DEVICE_REGISTRY_UPDATED,
{
"action": "create" if is_new else "update",
"device_id": device_id,
},
)

entity_registry = await self._hass.helpers.entity_registry.async_get_registry()

async def got_entity_registry_list(message):
for entry in message['result']:
entity_id = entry['entity_id']

entity_registry.devices[entity_id] = RegistryEntry(**entry)
device_registry.async_schedule_save()

self.hass.bus.async_fire(
EVENT_ENTITY_REGISTRY_UPDATED, {"action": "create", "entity_id": entity_id}
)

self._remove_listener = self._hass.bus.async_listen(EVENT_CALL_SERVICE, forward_event)

for event in self._subscribe_events:
await self._call(fire_event, 'subscribe_events', event_type=event)

#await self._call(device_registry_updated, 'device_registry_updated', event_type=event)

await self._call(got_device_registry_list, "config/device_registry/list")
await self._call(got_entity_registry_list, "config/entity_registry/list")

await self._call(got_states, 'get_states')