-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Add concentration level sensor to Aranet #137291
base: dev
Are you sure you want to change the base?
Changes from 12 commits
aee85a8
73226ba
1a7a651
209cd6b
16f7800
c522db9
c272a59
942ba37
cbb072a
cd71145
5ef98be
92d8b1c
ad7f512
67a33c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
from aranet4.client import Aranet4Advertisement | ||
from aranet4.client import Aranet4Advertisement, AranetType, Color | ||
from bleak.backends.device import BLEDevice | ||
|
||
from homeassistant.components.bluetooth.passive_update_processor import ( | ||
|
@@ -74,6 +74,11 @@ class AranetSensorEntityDescription(SensorEntityDescription): | |
native_unit_of_measurement=UnitOfPressure.HPA, | ||
state_class=SensorStateClass.MEASUREMENT, | ||
), | ||
"status": AranetSensorEntityDescription( | ||
key="concentration_level", | ||
name="Concentration Level", | ||
device_class=SensorDeviceClass.ENUM, | ||
), | ||
"co2": AranetSensorEntityDescription( | ||
key="co2", | ||
name="Carbon Dioxide", | ||
|
@@ -161,7 +166,11 @@ def sensor_update_to_bluetooth_data_update( | |
val = getattr(adv.readings, key) | ||
if val == -1: | ||
continue | ||
val *= desc.scale | ||
val = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this, can we set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, I think we should represent it same as the app does, also for the translations (was actually waiting to have time to search for example for the translations later, thanks @abmantis) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll add translations for the states instead.
I'm not sure if this would necessarily be the expectation. See #137291 (comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I did the translations correctly, and I haven't figured out how to test the translations programmatically. Could someone take a look at the latest changes and let me know if you have any further suggestions? |
||
get_friendly_status(val.name, adv.readings.type) | ||
if key == "status" | ||
else val * desc.scale | ||
) | ||
data[tag] = val | ||
names[tag] = desc.name | ||
descs[tag] = desc | ||
|
@@ -213,3 +222,17 @@ def available(self) -> bool: | |
def native_value(self) -> int | float | None: | ||
"""Return the native value.""" | ||
return self.processor.entity_data.get(self.entity_key) | ||
|
||
|
||
def get_friendly_status(status: Color, device_type: AranetType) -> str: | ||
"""Map status code to human-readable status based on device type.""" | ||
status_map = { | ||
"ERROR": "Error", | ||
"RED": "Unhealthy", | ||
(device_type.ARANET4, "GREEN"): "Good", | ||
(device_type.ARANET4, "YELLOW"): "Average", | ||
(device_type.ARANET_RADON, "GREEN"): "Normal", | ||
(device_type.ARANET_RADON, "YELLOW"): "Elevated", | ||
} | ||
|
||
return status_map.get((device_type, status), status_map.get(status, status)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for all the other sensors here we use the device key as the sensor key and translation_key.
should we use
status_level
for this one too, to keep it consistent?