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: expose sensor_id in sensors and alias in all features #176

Merged
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
4 changes: 4 additions & 0 deletions blebox_uniapi/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def device_class(self) -> str:
def product(self) -> "Box":
return self._product

@property
def alias(self):
return self._alias

# TODO: (cleanup) move to product/box ?
def raw_value(self, name: str) -> Any:
product = self._product
Expand Down
45 changes: 38 additions & 7 deletions blebox_uniapi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def many_from_config(cls, product, box_type_config, extended_state):
}

feature = constructor(
product=product, alias=alias, methods=materialized_methods
product=product,
alias=alias,
methods=materialized_methods,
sensor_id=sensor_id,
)
object_list.append(feature)

Expand All @@ -98,11 +101,18 @@ class BaseSensor(Feature):
_device_class: str
_native_value: Union[float, int, str]
_sensor_type: Optional[str]
_sensor_id: Optional[int]

def __init__(
self, product: "Box", alias: str, methods: dict, sensor_type: str = None
self,
product: "Box",
alias: str,
methods: dict,
sensor_type: str = None,
sensor_id: Optional[int] = None,
):
self._sensor_type = sensor_type
self._sensor_id = sensor_id
super().__init__(product, alias, methods)

@property
Expand All @@ -117,6 +127,14 @@ def device_class(self) -> str:
def native_value(self):
return self._native_value

@property
def sensor_id(self):
return self._sensor_id

@property
def probe_id(self):
return self.sensor_id

@classmethod
def many_from_config(cls, product, box_type_config, extended_state):
raise NotImplementedError("Please use SensorFactory")
Expand All @@ -143,14 +161,15 @@ def __init__(
product: "Box",
alias: str,
methods: dict,
sensor_id: Optional[int],
*,
# generalization params
sensor_type: str,
unit: str,
scale: float = 1,
precision: Optional[int] = None,
):
super().__init__(product, alias, methods)
super().__init__(product, alias, methods, sensor_id=sensor_id)
self._unit = unit
self._scale = scale
self._precision = precision
Expand Down Expand Up @@ -200,8 +219,14 @@ def _read_period_of_measurement(self) -> int:
class Temperature(BaseSensor):
_current: Union[float, int, None]

def __init__(self, product: "Box", alias: str, methods: dict):
super().__init__(product, alias, methods)
def __init__(
self,
product: "Box",
alias: str,
methods: dict,
sensor_id: Optional[int] = None,
):
super().__init__(product, alias, methods, sensor_id=sensor_id)
self._unit = "celsius"
self._device_class = "temperature"

Expand All @@ -227,8 +252,14 @@ def after_update(self) -> None:
class AirQuality(BaseSensor):
_pm: Optional[int]

def __init__(self, product: "Box", alias: str, methods: dict):
super().__init__(product, alias, methods)
def __init__(
self,
product: "Box",
alias: str,
methods: dict,
sensor_id: Optional[str] = None,
):
super().__init__(product, alias, methods, sensor_id)
self._unit = "concentration_of_mp"
self._device_class = alias

Expand Down
Loading