def create(client, name): """Create a virtual sensor. Create a virtual sensor with a name. """ sensor = Sensor.create(client, name=name) Sensor.display(client, [sensor])
def sensor(client, label, mac, **kwargs): """List sensors for a label. List sensors for a given LABEL. Add, remove or replace sensors from the LABEL by using the --add, --remove or --replace arguments respectively. Note that you can specify "none" with these to indicate an empty list. """ label = Label.lookup(client, label) actions = lookup_label_action_resources(client, Sensor, mac=mac, **kwargs) if actions.add is not None: label.add_sensors(actions.add) if actions.remove is not None: label.remove_sensors(actions.remove) if actions.replace is not None: label.update_sensors(actions.replace) sensors = label.sensors() Sensor.display(client, sensors, **kwargs)
def create(client, name): """Create a virtual sensor. Create a virtual sensor with a name. """ sensor = Sensor.create(client, attributes={'name': name}) Sensor.display(client, [sensor])
def label(client, sensor, mac): """Get the labels for a sensor. Gets all the labels that a given SENSOR is part of. """ sensor = Sensor.lookup(client, sensor, mac=mac) Sensor.display(client, sensor.labels())
def update(client, sensor, name, mac, **kwargs): """Updates the attributes of a sensor. Updates the attributes of a given SENSOR. """ sensor = Sensor.lookup(client, sensor, mac=mac) sensor = sensor.update(name=name) Sensor.display(client, [sensor])
def sensor(client, label, **kwargs): """Lists sensors for a label. Lists sensors for a given LABEL. """ label = Label.lookup(client, label, include=[Sensor]) sensors = label.sensors(use_included=True) Sensor.display(client, sensors, **kwargs)
def update(client, sensor, name, mac, **kwargs): """Updates the attributes of a sensor. Updates the attributes of a given SENSOR. """ sensor = Sensor.lookup(client, sensor, mac=mac) sensor = sensor.update(attributes={'name': name}) Sensor.display(client, [sensor])
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) Sensor.display(client, sensors, **kwargs)
def list(client, sensor, mac, **kwargs): """List sensors. Lists information for a given SENSOR or all sensors in the organization. """ if sensor: sensors = [Sensor.lookup(client, sensor, mac=mac)] else: sensors = Sensor.all(client) Sensor.display(client, sensors, **kwargs)
def list(client, sensor, mac, **kwargs): """List sensors. Lists information for a given SENSOR or all sensors in the organization. """ if sensor: sensors = [Sensor.lookup(client, sensor, mac=mac)] else: metadata = kwargs.get('metadata') or None sensors = Sensor.where(client, metadata=metadata) Sensor.display(client, sensors, **kwargs)
def validate_format(output, client, sensors, capsys): first_sensor = sensors[0] # With sort Sensor.display(client, sensors, format=output, sort='name') out, err = capsys.readouterr() assert first_sensor.short_id in out Sensor.display(client, sensors, format=output, sort='name', reverse=True) reversed, err = capsys.readouterr() assert reversed != out # Without sort Sensor.display(client, sensors, format=output) out, err = capsys.readouterr() assert first_sensor.short_id in out Sensor.display(client, sensors, format=output, reverse=True) reversed, err = capsys.readouterr() assert reversed != out
def test_formats(client, sensors, capsys): for output in ['csv', 'tabular', 'json']: validate_format(output, client, sensors, capsys) with pytest.raises(AttributeError): Sensor.display(client, sensors, format='xxx')