Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support for active power sensors on switchbox/switchboxd devices #175

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: "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: "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: "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: "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: "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: "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: "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
Loading