@cli.command() @click.argument('sensor') @device_mac_option @pass_client def delete(client, sensor, mac, **kwargs): """Delete a sensor. Deletes the SENSOR with the given id. """ sensor = Sensor.lookup(client, sensor, mac=mac) sensor.delete() click.echo("Deleted {}".format(sensor.id)) cli.add_command(timeseries.cli(Sensor)) @cli.command() @click.argument('sensor') @device_mac_option @pass_client def element(client, sensor, mac): """Get the element for a sensor. Gets the element a given SENSOR was last seen connected to. """ sensor = Sensor.lookup(client, sensor, mac=mac, include=[Element]) element = sensor.element(use_included=True) Element.display(client, [element] if element else [])
"""List labels. Lists information for a given LABEL or all labels in the organization. """ if label: labels = [Label.lookup(client, label, include=label_includes)] else: metadata = kwargs.get('metadata') or None labels = Label.where(client, include=label_includes, metadata=metadata) Label.display(client, labels, include=label_includes) cli.add_command( timeseries.cli(Label, history=False, writable=False, device=False)) @cli.command() @click.argument('name') @click.option('--sensors', type=ResourceParamType(metavar='SENSOR'), help="Add sensors to a label") @click.option('--elements', type=ResourceParamType(metavar='ELEMENT'), help="Add elements to a label") @click.pass_context def create(ctx, name, sensors, elements): """Create a label. Creates a label with a given NAME and an (optional) list of
@cli.command() @pass_client def list(client): """Display basic information of the organization. Displays basic attributes of the authorized organization. """ include = [User, Element, Sensor] org = Organization.singleton(client, include=include) Organization.display(client, [org], include=include) @cli.command() @click.option('--name', help="the new name for the organization") @pass_client def update(client, name): """Updates the attributes of the organization. Updates the attributes of the currently authorized organization. """ org = Organization.singleton(client) org = org.update(name=name) include = [User, Element, Sensor] org = Organization.singleton(client, include=include) Organization.display(client, [org], include=include) cli.add_command(timeseries.cli(Organization, singleton=True))
help="the new name for the element") @device_mac_option @pass_client def update(client, element, name, mac, **kwargs): """Updates the attributes of a element. Updates the attributes of a given ELEMENT. """ element = Element.lookup(client, element, mac=mac) element = element.update(name=name) include = [Sensor] element = Element.lookup(client, element.id, mac=mac, include=include) Element.display(client, [element], include=include) cli.add_command(timeseries.cli(Element)) @cli.command() @click.argument('element') @device_mac_option @device_sort_option @pass_client def sensor(client, element, mac, **kwargs): """Get the sensors for an element. Gets the sensors last known to be connected to a given ELEMENT. """ element = Element.lookup(client, element, mac=mac, include=[Sensor]) sensors = element.sensors(use_included=True)
@pass_client def update(client, element, name, mac, **kwargs): """Updates the attributes of a element. Updates the attributes of a given ELEMENT. """ element = Element.lookup(client, element, mac=mac) element = element.update(attributes={ 'name': name }) include = [Sensor] element = Element.lookup(client, element.id, mac=mac, include=include) Element.display(client, [element], include=include) cli.add_command(timeseries.cli(Element)) cli.add_command(metadata.cli(Element)) @cli.command() @click.argument('element') @device_mac_option @device_sort_option @pass_client def sensor(client, element, mac, **kwargs): """Get the sensors for an element. Gets the sensors last known to be connected to a given ELEMENT. """ element = Element.lookup(client, element, mac=mac, include=[Sensor])
@cli.command() @click.argument('sensor') @device_mac_option @pass_client def delete(client, sensor, mac, **kwargs): """Delete a sensor. Deletes the SENSOR with the given id. """ sensor = Sensor.lookup(client, sensor, mac=mac) sensor.delete() click.echo("Deleted {}".format(sensor.id)) cli.add_command(timeseries.cli(Sensor)) cli.add_command(metadata.cli(Sensor)) @cli.command() @click.argument('sensor') @device_mac_option @pass_client def element(client, sensor, mac): """Get the element for a sensor. Gets the element a given SENSOR was last seen connected to. """ sensor = Sensor.lookup(client, sensor, mac=mac, include=[Element]) element = sensor.element(use_included=True) Element.display(client, [element] if element else [])