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

Commit

Permalink
return timestamp in WS call (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
abmantis authored and Adminiuga committed Oct 10, 2019
1 parent 4aea068 commit ccbaf82
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit ccbaf82

Please sign in to comment.