Open jessicamillar opened 7 months ago
IIRC, Part 1 is already done.
The magic is:
class Config:
alias_generator = snake_to_camel
allow_population_by_field_name = True
for example, see this. alias_generator produces field names for serialization. allow_population_by_field_name allows you to use the snake case to set the value in python.
I was very excited to discover all this.
We should not need makers anymore. Instead:
The types just implement from_data_class
and to_data_class
.
@classmethod def from_data_class(cls, component: RESTPollerComponent) -> "RESTPollerComponentGt": def to_data_class(self) -> RESTPollerComponent:
The TypeNames for the new types are added to default_decoders.py
.
I was excited to discover that we can locate the functionality of the makers inside the type class.
Just for reference, I thought the outcome of previous discussions (a year ago?) was TypeName is the version. If the type changes in a non backwards compatible way, you create a new type with a new type name. Most changes should be backwards / forwards compatible.
Part 1: Enforcing uniformity of CamelCase for attributes and sub-attributes of GridWorks Types. (Also, enforcing that all GridWorks Types have a Version, which is a 3 digit numeric string. I've already added the Version for the new TankModule types so no change needed)
Note that this is only for the message in transmission as bytes. If you can find a way to have the python class objects have camel case attributes and tuple_to_type does the snake to camel translation, that would be great.
Relevant for:
in types/hubitat_tank_gt:
all classes in types/rest_poller_gt:
all classes in types/hubitat_poller_gt
Note that sub-attributes do NOT have to be types although they can be. So for example as it stands,
FibaroTempSensorSettingsGt
is NOT a GridWorks type as it does not have a TypeName or Version.Part 2) Add poll period (PollPeriodMs or PollPeriodSeconds at your discretion) as an attribute of the
FibaroTempSensorSettingsGt
. This will make our lives easier in the field as we work on calibrating the 3 tank modules George will be installing Weds/Thurs.Here is a before/after example (except with a single device instead of all 4). This is for a simulated tank module on my home computer with a fictitious hubitat.
], "hubitat_component_id": "67b46892-3ea7-4869-90d5-0ff39b84e603", "sensor_supply_voltage": 23.7 }, "TypeName": "hubitat.tank.component.gt", "Version": "000"
AFTER: { "ComponentAttributeClassId": "60ac199d-679a-49f7-9142-8ca3e6428a5f", "ComponentId": "8e92bcce-eceb-4d6c-b640-fe610b03b639", "DisplayName": "Tank Module <1> SN i007", "Tank": { "Devices": [ { "PollPeriodMs": 1000, "AnalogInputId": 1, "DeviceId": 1, "Enabled": true, "Exponent": 1, "FibaroComponentId": "7dd3921a-cd8a-4e54-aa6a-0659517a5810", "Rest": null, "StackDepth": 1, "TankLabel": "i007 A1 (Thermistor #1 TANK TOP)", "TelemetryNameGtEnumSymbol": "c89d0ba1", "TempUnitGtEnumSymbol": "ec14bd47" } ], "HubitatComponentId": "67b46892-3ea7-4869-90d5-0ff39b84e603", "SensorSupplyVoltage": 23.7 }, "TypeName": "hubitat.tank.component.gt", "Version": "001" }