Some sensors (like Temperature or EC) report measurements in two different units (e.g., Celsius vs Fahrenheit). To prevent creating two separate Home Assistant entities for the same physical measurement, use a shared SensorReferenceKey.
By assigning both SensorType entries the same key in SENSOR_DESCRIPTIONS, only the type present in the device's sensor array at runtime will be registered. The other is silently ignored.
Steps to add a new pair:
- Add both constants to
SensorType in const.py. - Add a single shared key to
SensorReferenceKey in const.py. - Register both types in
SENSOR_DESCRIPTIONS in sensor.py using the same key and translation_key.
# 1. const.py
class SensorType:
MY_SENSOR_UNIT_A = 42
MY_SENSOR_UNIT_B = 43
class SensorReferenceKey:
MY_SENSOR = "mySensor"
# 2. sensor.py
SensorType.MY_SENSOR_UNIT_A: ACInfinitySensorSensorEntityDescription(
key=SensorReferenceKey.MY_SENSOR,
native_unit_of_measurement="unit_a",
translation_key="my_sensor",
...
),
SensorType.MY_SENSOR_UNIT_B: ACInfinitySensorSensorEntityDescription(
key=SensorReferenceKey.MY_SENSOR,
native_unit_of_measurement="unit_b",
translation_key="my_sensor",
...
),