-
-
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
Draft
parkerbxyz
wants to merge
14
commits into
home-assistant:dev
Choose a base branch
from
parkerbxyz:aranet-threshold-level
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−5
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aee85a8
Add threshold level sensor description to Aranet component
parkerbxyz 73226ba
Use Color enum for status options
parkerbxyz 1a7a651
Add threshold level sensor tests for Aranet components
parkerbxyz 209cd6b
Rename `threshold_level` key to `status`
parkerbxyz 16f7800
Update test to expect 7 sensors instead of 6
parkerbxyz c522db9
Merge branch 'dev' into aranet-threshold-level
parkerbxyz c272a59
Map sensor status to more human-friendly strings
parkerbxyz 942ba37
Rename `threshold_level` key to `concentration_status`
parkerbxyz cbb072a
Update docstring for function
parkerbxyz cd71145
Simplify `get_friendly_status()`
parkerbxyz 5ef98be
Rename `concentration_status` to `concentration_level`
parkerbxyz 92d8b1c
Rename `concentration_status` to `concentration_level` in sensor tests
parkerbxyz ad7f512
Refactor concentration level handling and tests
parkerbxyz 67a33c8
Normalize concentration level status values to lowercase
parkerbxyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, Color | ||
from bleak.backends.device import BLEDevice | ||
|
||
from homeassistant.components.bluetooth.passive_update_processor import ( | ||
|
@@ -74,6 +74,13 @@ class AranetSensorEntityDescription(SensorEntityDescription): | |
native_unit_of_measurement=UnitOfPressure.HPA, | ||
state_class=SensorStateClass.MEASUREMENT, | ||
), | ||
"status": AranetSensorEntityDescription( | ||
key="concentration_level", | ||
translation_key="concentration_level", | ||
name="Concentration Level", | ||
device_class=SensorDeviceClass.ENUM, | ||
options=[status.name.lower() for status in Color], | ||
), | ||
"co2": AranetSensorEntityDescription( | ||
key="co2", | ||
name="Carbon Dioxide", | ||
|
@@ -161,7 +168,9 @@ def sensor_update_to_bluetooth_data_update( | |
val = getattr(adv.readings, key) | ||
if val == -1: | ||
continue | ||
val *= desc.scale | ||
if key == "status": | ||
val = val.name.lower() | ||
val = val * desc.scale | ||
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. should scaling be applied for the string? |
||
data[tag] = val | ||
names[tag] = desc.name | ||
descs[tag] = desc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,16 @@ | |
"no_devices_found": "No unconfigured Aranet devices found.", | ||
"outdated_version": "This device is using outdated firmware. Please update it to at least v1.2.0 and try again." | ||
} | ||
}, | ||
"entity": { | ||
"sensor": { | ||
"concentration_level": { | ||
"state": { | ||
"green": "Normal", | ||
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. should we also add |
||
"yellow": "Elevated", | ||
"red": "Unhealthy" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?