Skip to content

Commit

Permalink
feature: add support for active power sensors on switchbox/switchboxd…
Browse files Browse the repository at this point in the history
… devices
  • Loading branch information
swistakm committed Jun 4, 2024
1 parent 06038a0 commit 444b4f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions blebox_uniapi/box_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand All @@ -305,7 +307,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand All @@ -330,7 +334,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand All @@ -357,7 +363,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down Expand Up @@ -392,7 +400,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down Expand Up @@ -424,7 +434,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down Expand Up @@ -456,7 +468,9 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
# note: switchbox/switchboxD sensors are currently not indexed (singletons)
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"activePower": lambda x: f"sensors[?type == 'activePower']|[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down
4 changes: 3 additions & 1 deletion blebox_uniapi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def _sensor_states(extended_state: dict):
# note: probably we should iterate extended state in future if there
# are other api flavours other than multiSensor that provide sensors
states = extended_state.get("multiSensor", {}).get("sensors", [])

# note: but for now we are only able to support non-multisensor devices
# that provide sensor data in extended data payload root
states.extend(extended_state.get("sensors", []))
# note: power measuring feature predates multiSensor API, so we need a small
# shim to adapt older shape of power measuring schema to the new sensor API
if "powerMeasuring" in extended_state:
Expand Down

0 comments on commit 444b4f7

Please sign in to comment.