Skip to main content

Units

Definiton

API Payload

Class

class SiUnit:
"""
A class used to represent International System of Units (SI) in Altergo
...

Attributes
----------
id : str
The unique identifier of the SI unit
name : str
The name of the SI unit
created_at : datetime
The date and time when the SI unit was created
updated_at : datetime
The date and time when the SI unit was last updated
"""
id: Optional[str] = None
name: Optional[str] = None
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None


Setup

#Altergo parameters to connect with Client
ALTERGO_FACTORY_API= 'https://altergo.io/' #Default Factory API
ALTERGO_IOT_API= 'https://iot.altergo.io/' #Default IOT API
apiKey = "Your API KEY" #API key of the client

model_name='KB Demo' #Blueprint from which assset is made
serial_number='KB Demo_1'#Unique serial number to identify asset
info

API keys are user bound

from altergo_sdk.models.v2 import SiUnit
altergoApiKey = apiKey
_client = {
"apiKey": altergoApiKey,
"factory_api": ALTERGO_FACTORY_API,
"iot_api":ALTERGO_IOT_API
}
altergoApi = Client(**_client)

Create

To create a new SI Unit and add it to the platform, you will need to instanciate a SIUnit object and use the createSiUnit method

si_unit_of_temperature = '°C' # Symbol you want to be displayed for the unit
newSiUnitTemperature = SiUnit()
newSiUnitTemperature.name = si_unit_of_temperature

createdSiUnitTemperature = newAltergoClient.createSiUnit(
newSiUnit=newSiUnitTemperature
)

info

Unit name are usually the symbol for the unit. As seen in the example °C for temperature

Get

To get a SIUnit you can use the getSiUnits() method with a filterBy argument

retrievedSiUnit = getSiUnits(filterBy={"name": "°C"})
caution

This method returns a list

Update

To update an SiUnit you will first need to get it via the getSiUnits() method and then update it with updateSiUnit()

siUnitToUpdate = getSiUnits(filterBy={"name": "°C"})
siUnitToUpdate.name = "Kelvin"
response = updateSiUnit(updatedSiUnit = siUnitToUpdate)

Delete

To delete a SiUnit you will first need to get it via the getSiUnits() method and then delete it with deleteSiUnit()

siUnitToDelete = getSiUnits(filterBy={"name": "°C"})
response = deleteSiUnit(existingSiUnit = siUnitToDelete)