Device

class utils.Device(device_id: str, create_if_unknown: bool = False)

Bases: object

Individual Device

Parameters:
  • device_id – The unique ID of the device.
  • create_if_unknown – If the device_id is not known then create a new Device.

Methods Summary

add_reading(utc, field_values, commlink_name) Add a new reading for the device.
as_dict() Device represented as a dictionary
count() Count the number of readings for this device
fields(**kwargs) List all fields which this device has at some time reported values for.
get_commlinks() Get a list off commlinks which have provided data to this devices data
get_dtypes(category) Get the most recent reading from this devices data.
get_readings(**kwargs) Get the most recent reading from this devices data.
is_registered([setto]) Set/Get device registration status
last_reading() Get the most recent reading from this devices data.
set_name(name) Set a human readable name for the device.

Methods Documentation

add_reading(utc: str, field_values, commlink_name: str)

Add a new reading for the device.

Parameters:
  • utc – UTC timestamp as a string.
  • field_values (list of utils.FieldValues) – List of FieldValue objects
  • commlink_name – Name of the commulication link through which the reading was devivered
Raises:
as_dict()

Device represented as a dictionary

Returns: Device represented as a dictionary:

{
    "device_id": (str) The device ID,
    "registered": (bool) Is this device registered,
    "fields": {
        see fields for details
    },
    "last_update": last update,
    "last_upd_keys": last update keys
}
count()

Count the number of readings for this device

Returns:Number of readings for this device
Return type:int
fields(**kwargs)

List all fields which this device has at some time reported values for.

Keyword Arguments:
 only (list) – List of device_ids to which results should be limited.
Returns:List of Fields, each carrying information pertaining to the Field.
Return type:list of utils.Field

Get a list off commlinks which have provided data to this devices data

Returns:List of commlink names.
Return type:list
get_dtypes(category: str = None)

Get the most recent reading from this devices data.

Parameters:category (str) – What sub type of dtypes to return. Options: numbers, strings, booleans
Returns:List of acceptable data types.
Return type:list
get_readings(**kwargs)

Get the most recent reading from this devices data.

Keyword Arguments:
 
  • fill (str) – A fill mode for intervals with no data. Options:: “none” don’t fill and “null” fill intervals with null readings (defaults to none).
  • interval (int) – Reading interval in seconds. Readings are groupded into intervals (defaults to 5s).
  • metrics (list of utils.Metrics) – Limit fields to this lists field_ids (defaults to all)
  • start (arrow.arrow.Arrow) – Datetime start of search period (defaults to 1 hour ago)
  • end (arrow.arrow.Arrow) – Datetime end of search period (defaults to now)
  • limit (int) – Limit the number of readings (Max = 5000, Min = 1).
Returns:

Readings matching query.

Return type:

Readings

is_registered(setto=None) → bool

Set/Get device registration status

Parameters:setto (bool) – New registration status
Returns:Current registration status
last_reading()

Get the most recent reading from this devices data.

Returns:The most recent reading. last_upd_keys: The keys assosiated with the reading.
Return type:last_upd
set_name(name: str)

Set a human readable name for the device.

Parameters:name – New human readable name for the device