Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

return timestamp in WS call #2

Merged
merged 1 commit into from
Oct 10, 2019
Merged
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
13 changes: 12 additions & 1 deletion custom_components/zha_map/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import logging
import os
import time;
from datetime import timedelta

import voluptuous as vol
Expand Down Expand Up @@ -77,7 +78,10 @@ async def scan_now_handler(service):
async def websocket_get_devices(hass, connection, msg):
"""Get ZHA Map devices."""

response = [nei.json() for nei in builder.current.values()]
response = {
"time": builder.timestamp,
"devices": [nei.json() for nei in builder.current.values()]
}
connection.send_result(msg["id"], response)

websocket_api.async_register_command(hass, websocket_get_devices)
Expand All @@ -98,12 +102,18 @@ def __init__(self, hass, zha_gw):
self._seen = {}
self._current = {}
self._failed = {}
self._timestamp = 0

@property
def current(self):
"""Return a dict with all Router/Coordinator devices."""
return self._current

@property
def timestamp(self):
"""Return the timestamp of the last scan."""
return self._timestamp

async def time_tracker(self, time=None):
"""Awake periodically."""
if self._in_process and not self._in_process.done():
Expand Down Expand Up @@ -144,6 +154,7 @@ async def build(self):

await self.sanity_check()
self._current = {**self._seen}
self._timestamp = time.time()

def _pending(self):
"""Return neighbours still pending a scan."""
Expand Down