Skip to content

Commit

Permalink
Show last_seen only if offline
Browse files Browse the repository at this point in the history
  • Loading branch information
damarco committed Sep 16, 2018
1 parent a27e2b4 commit a02e325
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ async def async_device_initialized(self, device, join):
if endpoint_id == 0: # ZDO
continue

if endpoint.manufacturer is not None:
device_manufacturer = endpoint.manufacturer
if endpoint.model is not None:
device_model = endpoint.model

component = None
profile_clusters = ([], [])
device_key = "{}-{}".format(device.ieee, endpoint_id)
Expand Down Expand Up @@ -392,7 +397,6 @@ def __init__(self, device, manufacturer, model, application_listener,
self._device_state_attributes = {
'nwk': '0x{0:04x}'.format(device.nwk),
'ieee': str(device.ieee),
'last_seen': None,
'lqi': device.lqi,
'rssi': device.rssi,
}
Expand Down Expand Up @@ -432,10 +436,13 @@ def state(self) -> str:
def device_state_attributes(self):
"""Return device specific state attributes."""
update_time = None
if self._device.last_seen is not None:
if self._device.last_seen is not None and self._state == 'offline':
time_struct = time.localtime(self._device.last_seen)
update_time = time.strftime("%Y-%m-%dT%H:%M:%S", time_struct)
self._device_state_attributes['last_seen'] = update_time
self._device_state_attributes['last_seen'] = update_time
if ('last_seen' in self._device_state_attributes and
self._state != 'offline'):
del self._device_state_attributes['last_seen']
self._device_state_attributes['lqi'] = self._device.lqi
self._device_state_attributes['rssi'] = self._device.rssi
return self._device_state_attributes
Expand Down

0 comments on commit a02e325

Please sign in to comment.