Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion homeassistant/components/zha/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def async_configure(self):
await self._execute_listener_tasks('async_configure')
_LOGGER.debug('%s: completed configuration', self.name)

async def async_initialize(self, from_cache):
async def async_initialize(self, from_cache=False):
"""Initialize listeners."""
_LOGGER.debug('%s: started initialization', self.name)
await self._execute_listener_tasks('async_initialize', from_cache)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zha/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def async_device_initialized(self, device, is_new_join):
))
await asyncio.gather(*endpoint_tasks)

await zha_device.async_initialize(not is_new_join)
await zha_device.async_initialize(from_cache=(not is_new_join))

discovery_tasks = []
for discovery_info in discovery_infos:
Expand Down
15 changes: 13 additions & 2 deletions homeassistant/components/zha/device_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import time

from homeassistant.core import callback
from homeassistant.util import slugify
from .entity import ZhaEntity
from .const import LISTENER_BATTERY, SIGNAL_STATE_ATTR
Expand All @@ -30,6 +31,9 @@
255: 'Unknown'
}

STATE_ONLINE = 'online'
STATE_OFFLINE = 'offline'


class ZhaDeviceEntity(ZhaEntity):
"""A base class for ZHA devices."""
Expand Down Expand Up @@ -108,13 +112,20 @@ async def async_update(self):
difference = time.time() - self._zha_device.last_seen
if difference > self._keepalive_interval:
self._zha_device.update_available(False)
self._state = None
else:
self._zha_device.update_available(True)
self._state = 'online'
if self._battery_listener:
await self.async_get_latest_battery_reading()

@callback
def async_set_available(self, available):
Comment thread
MartinHjelmare marked this conversation as resolved.
"""Set entity availability."""
if available:
self._state = STATE_ONLINE
else:
self._state = STATE_OFFLINE
super().async_set_available(available)

async def _async_init_battery_values(self):
"""Get initial battery level and battery info from listener cache."""
battery_size = await self._battery_listener.get_attribute_value(
Expand Down