Skip to content

Commit

Permalink
fix: rectify ambiguity around powerConsumption and wind sensor types
Browse files Browse the repository at this point in the history
  • Loading branch information
swistakm committed Jun 4, 2024
1 parent 018ab6e commit 0b00027
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
14 changes: 7 additions & 7 deletions blebox_uniapi/box_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand All @@ -305,7 +305,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand All @@ -330,7 +330,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand All @@ -357,7 +357,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down Expand Up @@ -392,7 +392,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down Expand Up @@ -424,7 +424,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down Expand Up @@ -456,7 +456,7 @@ def get_latest_api_level(product_type: str) -> Union[dict, int]:
[
"switchBox.energy",
{
"powerMeasurement": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"powerConsumption": lambda x: "powerMeasuring.powerConsumption[0]|value ",
"periodS": "powerMeasuring.powerConsumption[0]|periodS",
"measurement_enabled": "powerMeasuring.enabled",
},
Expand Down
15 changes: 3 additions & 12 deletions blebox_uniapi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _sensor_states(extended_state: dict):
power_states = extended_state["powerMeasuring"].get("powerConsumption", [])
# note: be careful of names as this has been historically named differently
# in home-assistant
states.extend({"type": "powerMeasurement", **s} for s in power_states)
states.extend({"type": "powerConsumption", **s} for s in power_states)
return states

@classmethod
Expand Down Expand Up @@ -133,6 +133,7 @@ def __str__(self):
@SensorFactory.register("forwardActiveEnergy", unit="kWh")
@SensorFactory.register("illuminance", unit="lx", scale=100)
@SensorFactory.register("humidity", unit="percentage", scale=100)
@SensorFactory.register("wind", unit="m/s", scale=10)
class GenericSensor(BaseSensor):
def __init__(
# base sensor params
Expand Down Expand Up @@ -173,17 +174,7 @@ def after_update(self):
self._native_value = native


@SensorFactory.register("wind", unit="m/s", scale=10)
class Wind(GenericSensor):
@property
def device_class(self):
# compat/legacy: this sensor is advertised in homeassistant as wind speed
# despite different sensor-type naming. Keep it consistent until we rectiify
# this upstream
return "wind_speed"


@SensorFactory.register("powerMeasurement", unit="kWh")
@SensorFactory.register("powerConsumption", unit="kWh")
class PowerConsumption(GenericSensor):
# note: almost the same as typical generic sensor but also provides extra property
# to read last reset value
Expand Down

0 comments on commit 0b00027

Please sign in to comment.