Add support for BH1750 illuminance sensor in Nettigo Air Monitor integration (#140242)

* Add support for BH1750 illuminance sensor

* Update strings

* Update test snapshot
This commit is contained in:
Maciej Bieniek 2025-03-10 09:38:44 +01:00 committed by GitHub
parent a3e981f148
commit e831b1b230
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 72 additions and 1 deletions

View File

@ -11,6 +11,7 @@ SUFFIX_P1: Final = "_p1"
SUFFIX_P2: Final = "_p2"
SUFFIX_P4: Final = "_p4"
ATTR_BH1750_ILLUMINANCE: Final = "bh1750_illuminance"
ATTR_BME280_HUMIDITY: Final = "bme280_humidity"
ATTR_BME280_PRESSURE: Final = "bme280_pressure"
ATTR_BME280_TEMPERATURE: Final = "bme280_temperature"

View File

@ -19,6 +19,7 @@ from homeassistant.components.sensor import (
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION,
LIGHT_LUX,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
EntityCategory,
@ -33,6 +34,7 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.dt import utcnow
from .const import (
ATTR_BH1750_ILLUMINANCE,
ATTR_BME280_HUMIDITY,
ATTR_BME280_PRESSURE,
ATTR_BME280_TEMPERATURE,
@ -83,6 +85,15 @@ class NAMSensorEntityDescription(SensorEntityDescription):
SENSORS: tuple[NAMSensorEntityDescription, ...] = (
NAMSensorEntityDescription(
key=ATTR_BH1750_ILLUMINANCE,
translation_key="bh1750_illuminance",
suggested_display_precision=0,
native_unit_of_measurement=LIGHT_LUX,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
value=lambda sensors: sensors.bh1750_illuminance,
),
NAMSensorEntityDescription(
key=ATTR_BME280_HUMIDITY,
translation_key="bme280_humidity",

View File

@ -54,6 +54,9 @@
},
"entity": {
"sensor": {
"bh1750_illuminance": {
"name": "BH1750 illuminance"
},
"bme280_humidity": {
"name": "BME280 humidity"
},

View File

@ -26,6 +26,7 @@
{ "value_type": "temperature", "value": "6.26" },
{ "value_type": "HECA_temperature", "value": "7.95" },
{ "value_type": "HECA_humidity", "value": "49.97" },
{ "value_type": "ambient_light", "value": "298.45" },
{ "value_type": "signal", "value": "-72" }
]
}

View File

@ -2,7 +2,7 @@
# name: test_entry_diagnostics
dict({
'data': dict({
'bh1750_illuminance': None,
'bh1750_illuminance': 298.45,
'bme280_humidity': 45.69,
'bme280_pressure': 1011.0117,
'bme280_temperature': 7.56,

View File

@ -1,4 +1,59 @@
# serializer version: 1
# name: test_sensor[sensor.nettigo_air_monitor_bh1750_illuminance-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.nettigo_air_monitor_bh1750_illuminance',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 0,
}),
}),
'original_device_class': <SensorDeviceClass.ILLUMINANCE: 'illuminance'>,
'original_icon': None,
'original_name': 'BH1750 illuminance',
'platform': 'nam',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'bh1750_illuminance',
'unique_id': 'aa:bb:cc:dd:ee:ff-bh1750_illuminance',
'unit_of_measurement': 'lx',
})
# ---
# name: test_sensor[sensor.nettigo_air_monitor_bh1750_illuminance-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'illuminance',
'friendly_name': 'Nettigo Air Monitor BH1750 illuminance',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'lx',
}),
'context': <ANY>,
'entity_id': 'sensor.nettigo_air_monitor_bh1750_illuminance',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '298.45',
})
# ---
# name: test_sensor[sensor.nettigo_air_monitor_bme280_humidity-entry]
EntityRegistryEntrySnapshot({
'aliases': set({