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

Commit

Permalink
Use device-type in sensor and element listings
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Feb 10, 2017
1 parent c1d44a1 commit e446540
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
8 changes: 6 additions & 2 deletions helium_commander/element.py
Expand Up @@ -3,8 +3,11 @@


def display_map(cls, client, include=None):
def _type(self):
return getattr(self.meta, "device_type", None)

def _mac(self):
return self.meta.mac
return getattr(self.meta, "mac", None)

def _count_sensor(self):
return len(self.sensors(use_included=True))
Expand All @@ -21,7 +24,8 @@ def _name(self):

dict = super(Element, cls).display_map(client, include=include)
dict.update([
('mac', _mac)
('mac', _mac),
('type', _type)
])

if include and Sensor in include:
Expand Down
16 changes: 1 addition & 15 deletions helium_commander/sensor.py
Expand Up @@ -3,21 +3,7 @@
from operator import attrgetter


def card_type(card_id, default):
return {
'2': 'blue',
'5': 'green',
}.get(card_id, default)


def display_map(cls, client, include=None):
def _type(self):
try:
card = str(self.meta.card.get('id'))
return card_type(card, card)
except AttributeError:
return None

def _meta(attr):
def func(self):
return getattr(self.meta, attr, None)
Expand All @@ -26,7 +12,7 @@ def func(self):
dict = super(Sensor, cls).display_map(client, include=include)
dict.update([
('mac', _meta('mac')),
('type', _type),
('type', _meta('device_type')),
('created', _meta('created')),
('seen', _meta('last_seen')),
('name', attrgetter('name'))
Expand Down

0 comments on commit e446540

Please sign in to comment.