Skip to content
This repository has been archived by the owner on Feb 15, 2018. It is now read-only.

Commit

Permalink
Safeguard for missing sensors or name
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Sep 23, 2016
1 parent b08e001 commit b07db16
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions helium_commander/element.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from __future__ import unicode_literals
from helium import Element
from operator import attrgetter


def display_map(cls, client):
def _mac(self):
return self.meta.mac

def _count_sensor(self):
return len(self.sensors(use_included=True))
try:
return len(self.sensors(use_included=True))
except AttributeError:
pass
return None

def _seen(self):
try:
Expand All @@ -17,12 +20,15 @@ def _seen(self):
pass
return None

def _name(self):
return getattr(self, 'name', None)

dict = super(Element, cls).display_map(client)
dict.update([
('mac', _mac),
('sensors', _count_sensor),
('seen', _seen),
('name', attrgetter('name')),
('name', _name)
])
return dict

Expand Down

0 comments on commit b07db16

Please sign in to comment.