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

Commit

Permalink
Added element support to Label
Browse files Browse the repository at this point in the history
Labels can now contain sensors and elements. This adds support to
Label for manipulating sensor and element membership during creation
and update.
  • Loading branch information
madninja committed Jan 24, 2017
1 parent 58bfb59 commit eac06f2
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 6 deletions.
19 changes: 13 additions & 6 deletions helium/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from . import (
Resource,
Sensor,
Element,
to_many,
timeseries,
metadata,
Expand All @@ -12,17 +13,23 @@


@to_many(Sensor, writable=True, reverse=to_many)
@to_many(Element, writable=True, reverse=to_many)
@timeseries()
@metadata()
class Label(Resource):
@classmethod
def create(cls, session,
attributes=None, sensors=None, **kwargs):
if sensors is not None:
def create(cls, session, attributes=None,
sensors=None, elements=None, **kwargs):

def _relate_resources(name, type, resources):
if resources is None:
return
relationships = kwargs.setdefault('relationships', {})
sensor_ids = [r.id for r in sensors]
relationships['sensor'] = build_request_relationship('sensor',
sensor_ids)
resource_ids = [r.id for r in resources]
relationships[name] = build_request_relationship(type,
resource_ids)
_relate_resources('sensor', 'sensor', sensors)
_relate_resources('element', 'element', elements)

return super(Label, cls).create(session,
attributes=attributes,
Expand Down
Loading

0 comments on commit eac06f2

Please sign in to comment.