Skip to content

Commit

Permalink
Hubitat and HubitatTank components
Browse files Browse the repository at this point in the history
  • Loading branch information
anschweitzer committed Oct 13, 2023
1 parent e3460a0 commit 4842246
Show file tree
Hide file tree
Showing 26 changed files with 1,057 additions and 261 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gridworks-protocol"
version = "0.5.8.dev0"
version = "0.5.8.dev1"
description = "Gridworks Protocol"
authors = ["Jessica Millar <[email protected]>"]
license = "MIT"
Expand Down
3 changes: 0 additions & 3 deletions src/gwproto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import gwproto.enums as enums
import gwproto.messages as messages
import gwproto.property_format as property_format
from gwproto.data_classes.hardware_layout import HardwareLayout
from gwproto.data_classes.sh_node import ShNode
from gwproto.decoders import CallableDecoder
Expand Down
5 changes: 5 additions & 0 deletions src/gwproto/data_classes/cacs/fibaro_smart_implant_cac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gwproto.data_classes.component_attribute_class import ComponentAttributeClass


class FibaroSmartImplantCac(ComponentAttributeClass):
...
5 changes: 0 additions & 5 deletions src/gwproto/data_classes/cacs/fibaro_tank_temp_sensor_cac.py

This file was deleted.

5 changes: 5 additions & 0 deletions src/gwproto/data_classes/cacs/hubitat_cac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gwproto.data_classes.component_attribute_class import ComponentAttributeClass


class HubitatCac(ComponentAttributeClass):
...
5 changes: 5 additions & 0 deletions src/gwproto/data_classes/cacs/hubitat_tank_module_cac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gwproto.data_classes.component_attribute_class import ComponentAttributeClass


class HubitatTankModuleCac(ComponentAttributeClass):
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import Optional

from gwproto.data_classes.component import Component


class FibaroSmartImplantComponent(Component):
def __init__(
self,
component_id: str,
component_attribute_class_id: str,
display_name: Optional[str] = None,
hw_uid: Optional[str] = None,
):
super().__init__(
component_id=component_id,
component_attribute_class_id=component_attribute_class_id,
display_name=display_name,
hw_uid=hw_uid,
)

This file was deleted.

29 changes: 29 additions & 0 deletions src/gwproto/data_classes/components/hubitat_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional

from gwproto.data_classes.component import Component


class HubitatComponent(Component):
host: str
maker_api_id: int
access_token: str

def __init__(
self,
component_id: str,
component_attribute_class_id: str,
host: str,
maker_api_id: int,
access_token: str,
display_name: Optional[str] = None,
hw_uid: Optional[str] = None,
):
self.host = host
self.maker_api_id = maker_api_id
self.access_token = access_token
super().__init__(
component_id=component_id,
component_attribute_class_id=component_attribute_class_id,
display_name=display_name,
hw_uid=hw_uid,
)
83 changes: 83 additions & 0 deletions src/gwproto/data_classes/components/hubitat_tank_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Optional

from gwproto.data_classes.component import Component
from gwproto.data_classes.sh_node import ShNode
from gwproto.types.hubitat_component_gt import HubitatComponentGt
from gwproto.types.hubitat_component_gt import HubitatRESTResolutionSettings
from gwproto.types.hubitat_tank_gt import DEFAULT_SENSOR_NODE_NAME_FORMAT
from gwproto.types.hubitat_tank_gt import FibaroTempSensorSettings
from gwproto.types.hubitat_tank_gt import FibaroTempSensorSettingsGt
from gwproto.types.hubitat_tank_gt import HubitatTankSettingsGt


class HubitatTankComponent(Component):
hubitat: HubitatComponentGt
devices_gt: list[FibaroTempSensorSettingsGt]
devices: list[FibaroTempSensorSettings] = []

def __init__(
self,
component_id: str,
component_attribute_class_id: str,
tank_gt: HubitatTankSettingsGt,
display_name: Optional[str] = None,
hw_uid: Optional[str] = None,
):
# Create self.hubitat as a proxy containing only the id
# of the hubitat; the actual component data will be resolved
# when resolve() is called; Here in the constructor we cannot
# rely on the actual HubitatComponentGt existing yet.
self.hubitat = HubitatComponentGt(
ComponentId=tank_gt.hubitat_component_id,
ComponentAttributeClassId="",
Host="",
MakerApiId=0,
AccessToken="",
)
self.devices_gt = list(tank_gt.devices)
super().__init__(
display_name=display_name,
component_id=component_id,
hw_uid=hw_uid,
component_attribute_class_id=component_attribute_class_id,
)

def resolve(
self,
tank_node_name: str,
components: dict[str, Component],
nodes: dict[str, ShNode],
node_name_format=DEFAULT_SENSOR_NODE_NAME_FORMAT,
):
hubitat_component = components.get(self.hubitat.ComponentId, None)
if hubitat_component is None:
raise ValueError(
"ERROR. No component found for "
f"HubitatTankComponent.hubitat.CompnentId {self.hubitat.ComponentId}"
)
if not isinstance(hubitat_component, HubitatComponentGt):
raise ValueError(
"ERROR. Referenced hubitat component has type "
f"{type(hubitat_component)}; "
"must be instance of HubitatComponentGt. "
f"Hubitat component id: {self.hubitat.ComponentId}"
)
hubitat_settings = HubitatRESTResolutionSettings(hubitat_component)
devices = [
FibaroTempSensorSettings.create(
tank_name=tank_node_name,
settings_gt=device_gt,
hubitat=hubitat_settings,
node_name_format=node_name_format,
)
for device_gt in self.devices_gt
]
for device in devices:
if device.node_name not in nodes:
raise ValueError(
f"ERROR. Node not found for tank temp sensor <{device.node_name}>"
)
# replace proxy hubitat component, which only had component id.
# with the actual hubitat component containing data.
self.hubitat = hubitat_component
self.devices = devices
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class RESTPollerComponent(Component):
rest = RESTPollerSettings
rest: RESTPollerSettings

def __init__(
self,
Expand Down
16 changes: 14 additions & 2 deletions src/gwproto/default_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
from typing import Type
from typing import TypeVar

import gwproto.types.fibaro_smart_implant_cac_gt
import gwproto.types.fibaro_smart_implant_component_gt
import gwproto.types.hubitat_cac_gt
import gwproto.types.hubitat_component_gt
import gwproto.types.hubitat_tank_cac_gt
import gwproto.types.hubitat_tank_component_gt
import gwproto.types.rest_poller_cac_gt
import gwproto.types.rest_poller_component_gt
from gwproto.data_classes.component import Component
from gwproto.data_classes.component_attribute_class import ComponentAttributeClass
from gwproto.decoders import PydanticTypeNameDecoder
Expand Down Expand Up @@ -71,15 +79,19 @@ def decode_to_data_class(
default_cac_decoder = CacDecoder(
model_name="DefaultCacDecoder",
module_names=[
"gwproto.types.fibaro_smart_implant_cac_gt",
"gwproto.types.hubitat_cac_gt",
"gwproto.types.hubitat_tank_cac_gt",
"gwproto.types.rest_poller_cac_gt",
"gwproto.types.fibaro_tank_temp_sensor_cac_gt",
],
)

default_component_decoder = ComponentDecoder(
model_name="DefaultComponentDecoder",
module_names=[
"gwproto.types.fibaro_smart_implant_component_gt",
"gwproto.types.hubitat_component_gt",
"gwproto.types.hubitat_tank_component_gt",
"gwproto.types.rest_poller_component_gt",
"gwproto.types.fibaro_tank_temp_sensor_component_gt",
],
)
2 changes: 1 addition & 1 deletion src/gwproto/enums/actor_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ActorClass(StrEnum):
MultipurposeSensor = auto()
Thermostat = auto()
HubitatTelemetryReader = auto()
FibaroTankTempSensor = auto()
HubitatTankModule = auto()

@classmethod
def default(cls) -> "ActorClass":
Expand Down
44 changes: 34 additions & 10 deletions src/gwproto/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
from gwproto.types.egauge_register_config import EgaugeRegisterConfig_Maker
from gwproto.types.electric_meter_cac_gt import ElectricMeterCacGt
from gwproto.types.electric_meter_cac_gt import ElectricMeterCacGt_Maker
from gwproto.types.fibaro_tank_temp_sensor_cac_gt import FibaroTankTempSensorCacGt
from gwproto.types.fibaro_tank_temp_sensor_cac_gt import FibaroTankTempSensorCacGt_Maker
from gwproto.types.fibaro_tank_temp_sensor_component_gt import (
FibaroTankTempSensorComponentGt,
from gwproto.types.fibaro_smart_implant_cac_gt import FibaroSmartImplantCacGt
from gwproto.types.fibaro_smart_implant_cac_gt import FibaroSmartImplantCacGt_Maker
from gwproto.types.fibaro_smart_implant_component_gt import (
FibaroSmartImplantComponentGt,
)
from gwproto.types.fibaro_tank_temp_sensor_component_gt import (
FibaroTankTempSensorComponentGt_Maker,
from gwproto.types.fibaro_smart_implant_component_gt import (
FibaroSmartImplantComponentGt_Maker,
)
from gwproto.types.gt_dispatch_boolean import GtDispatchBoolean
from gwproto.types.gt_dispatch_boolean import GtDispatchBoolean_Maker
Expand Down Expand Up @@ -52,6 +52,18 @@
from gwproto.types.gt_telemetry import GtTelemetry_Maker
from gwproto.types.heartbeat_b import HeartbeatB
from gwproto.types.heartbeat_b import HeartbeatB_Maker
from gwproto.types.hubitat_cac_gt import HubitatCacGt
from gwproto.types.hubitat_cac_gt import HubitatCacGt_Maker
from gwproto.types.hubitat_component_gt import HubitatComponentGt
from gwproto.types.hubitat_component_gt import HubitatComponentGt_Maker
from gwproto.types.hubitat_component_gt import HubitatRESTResolutionSettings
from gwproto.types.hubitat_tank_cac_gt import HubitatTankCacGt
from gwproto.types.hubitat_tank_cac_gt import HubitatTankCacGt_Maker
from gwproto.types.hubitat_tank_component_gt import HubitatTankComponentGt
from gwproto.types.hubitat_tank_component_gt import HubitatTankComponentGt_Maker
from gwproto.types.hubitat_tank_gt import FibaroTempSensorSettings
from gwproto.types.hubitat_tank_gt import FibaroTempSensorSettingsGt
from gwproto.types.hubitat_tank_gt import HubitatTankSettingsGt
from gwproto.types.multipurpose_sensor_cac_gt import MultipurposeSensorCacGt
from gwproto.types.multipurpose_sensor_cac_gt import MultipurposeSensorCacGt_Maker
from gwproto.types.pipe_flow_sensor_cac_gt import PipeFlowSensorCacGt
Expand Down Expand Up @@ -110,10 +122,12 @@
"ElectricMeterCacGt_Maker",
# "ElectricMeterComponentGt",
# "ElectricMeterComponentGt_Maker",
"FibaroTankTempSensorCacGt",
"FibaroTankTempSensorCacGt_Maker",
"FibaroTankTempSensorComponentGt",
"FibaroTankTempSensorComponentGt_Maker",
"FibaroTempSensorSettingsGt",
"FibaroTempSensorSettings",
"FibaroSmartImplantCacGt",
"FibaroSmartImplantCacGt_Maker",
"FibaroSmartImplantComponentGt",
"FibaroSmartImplantComponentGt_Maker",
"GtDispatchBoolean",
"GtDispatchBoolean_Maker",
"GtDispatchBooleanLocal",
Expand All @@ -136,6 +150,16 @@
"GtTelemetry_Maker",
"HeartbeatB",
"HeartbeatB_Maker",
"HubitatCacGt",
"HubitatCacGt_Maker",
"HubitatComponentGt",
"HubitatComponentGt_Maker",
"HubitatRESTResolutionSettings",
"HubitatTankCacGt",
"HubitatTankCacGt_Maker",
"HubitatTankComponentGt",
"HubitatTankComponentGt_Maker",
"HubitatTankSettingsGt",
"MultipurposeSensorCacGt",
"MultipurposeSensorCacGt_Maker",
# "MultipurposeSensorComponentGt",
Expand Down
Loading

0 comments on commit 4842246

Please sign in to comment.