Skip to content

Commit

Permalink
account for Celcius temperature sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
dalinicus committed Jan 31, 2025
1 parent 065b362 commit 15b6774
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
19 changes: 16 additions & 3 deletions custom_components/ac_infinity/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Constants for the AC Infinity integration."""

from homeassistant.const import Platform

MANUFACTURER = "AC Infinity"
Expand All @@ -16,6 +15,7 @@
CONF_POLLING_INTERVAL = "polling_interval"
CONF_UPDATE_PASSWORD = "update_password"
DEFAULT_POLLING_INTERVAL = 10
ISSUE_URL = "https://github.com/dalinicus/homeassistant-acinfinity/issues/new?template=Blank+issue"


class CustomPortPropertyKey:
Expand Down Expand Up @@ -58,16 +58,29 @@ class SensorPropertyKey:


class SensorType:
PROBE_TEMPERATURE = 0
PROBE_TEMPERATURE_F = 0
PROBE_TEMPERATURE_C = 1
PROBE_HUMIDITY = 2
PROBE_VPD = 3
EXTERNAL_TEMPERATURE = 4
EXTERNAL_TEMPERATURE_F = 4
EXTERNAL_TEMPERATURE_C = 4
EXTERNAL_HUMIDITY = 6
EXTERNAL_VPD = 7
CO2 = 11
LIGHT = 12


class SensorKeys:
PROBE_TEMPERATURE = "probeTemperature"
PROBE_HUMIDITY = "probeHumidity"
PROBE_VPD = "probeVaporPressureDeficit"
EXTERNAL_TEMPERATURE = "externalTemperature"
EXTERNAL_HUMIDITY = "externalHumidity"
EXTERNAL_VPD = "externalVaporPressureDeficit"
CO2_SENSOR = "co2Sensor"
LIGHT_SENSOR = "lightSensor"


# noinspection SpellCheckingInspection
class PortPropertyKey:
# /api/dev/devInfoListAll via "ports" property
Expand Down
6 changes: 3 additions & 3 deletions custom_components/ac_infinity/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __get_device_info(
controller: ACInfinityController, sensor_port: int, sensor_type: int
):
match sensor_type:
case SensorType.PROBE_TEMPERATURE | SensorType.PROBE_HUMIDITY | SensorType.PROBE_VPD:
case SensorType.PROBE_TEMPERATURE_F | SensorType.PROBE_TEMPERATURE_C | SensorType.PROBE_HUMIDITY | SensorType.PROBE_VPD:
return DeviceInfo(
identifiers={
(DOMAIN, f"{controller.device_id}_{sensor_port}_spc24")
Expand All @@ -181,7 +181,7 @@ def __get_device_info(
via_device=controller.identifier,
model="UIS CO2 + Light Sensor (AC-COS3)",
)
case SensorType.EXTERNAL_TEMPERATURE | SensorType.EXTERNAL_HUMIDITY | SensorType.EXTERNAL_VPD:
case SensorType.EXTERNAL_TEMPERATURE_F | SensorType.EXTERNAL_HUMIDITY | SensorType.EXTERNAL_VPD:
return controller.device_info
case _:
return DeviceInfo(
Expand Down Expand Up @@ -912,7 +912,7 @@ def __init__(
@property
def unique_id(self) -> str:
"""Return the unique ID for this entity."""
return f"{DOMAIN}_{self._sensor.controller.mac_addr}_port_{self._sensor.sensor_port}_{self._sensor.sensor_type}"
return f"{DOMAIN}_{self._sensor.controller.mac_addr}_sensor_{self._sensor.sensor_port}_{self.entity_description.key}"

@property
def device_info(self) -> DeviceInfo:
Expand Down
58 changes: 44 additions & 14 deletions custom_components/ac_infinity/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@

from .const import (
DOMAIN,
ISSUE_URL,
ControllerPropertyKey,
CustomPortPropertyKey,
PortPropertyKey,
SensorKeys,
SensorPropertyKey,
SensorType,
)
Expand Down Expand Up @@ -265,9 +267,19 @@ def __get_next_mode_change_timestamp(
]

SENSOR_DESCRIPTIONS: dict[int, ACInfinitySensorSensorEntityDescription] = {
SensorType.PROBE_TEMPERATURE: ACInfinitySensorSensorEntityDescription(
# key is not used for sensors.
key="probeTemperature",
SensorType.PROBE_TEMPERATURE_F: ACInfinitySensorSensorEntityDescription(
key=SensorKeys.PROBE_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
icon=None, # default
translation_key="probe_temperature",
suggested_unit_of_measurement=None,
suitable_fn=__suitable_fn_sensor_temperature,
get_value_fn=__get_value_fn_sensor_value_temperature,
),
SensorType.PROBE_TEMPERATURE_C: ACInfinitySensorSensorEntityDescription(
key=SensorKeys.PROBE_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand All @@ -278,7 +290,7 @@ def __get_next_mode_change_timestamp(
get_value_fn=__get_value_fn_sensor_value_temperature,
),
SensorType.PROBE_HUMIDITY: ACInfinitySensorSensorEntityDescription(
key="probeHumidity",
key=SensorKeys.PROBE_HUMIDITY,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
Expand All @@ -289,7 +301,7 @@ def __get_next_mode_change_timestamp(
get_value_fn=__get_value_fn_sensor_value_default,
),
SensorType.PROBE_VPD: ACInfinitySensorSensorEntityDescription(
key="probeVaporPressureDeficit",
key=SensorKeys.PROBE_VPD,
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
suggested_unit_of_measurement=UnitOfPressure.KPA,
Expand All @@ -299,8 +311,19 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
SensorType.EXTERNAL_TEMPERATURE: ACInfinitySensorSensorEntityDescription(
key="externalTemperature",
SensorType.EXTERNAL_TEMPERATURE_F: ACInfinitySensorSensorEntityDescription(
key=SensorKeys.EXTERNAL_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
icon=None, # default
translation_key="external_temperature",
suggested_unit_of_measurement=None,
suitable_fn=__suitable_fn_sensor_temperature,
get_value_fn=__get_value_fn_sensor_value_temperature,
),
SensorType.EXTERNAL_TEMPERATURE_C: ACInfinitySensorSensorEntityDescription(
key=SensorKeys.EXTERNAL_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand All @@ -311,7 +334,7 @@ def __get_next_mode_change_timestamp(
get_value_fn=__get_value_fn_sensor_value_temperature,
),
SensorType.EXTERNAL_HUMIDITY: ACInfinitySensorSensorEntityDescription(
key="externalHumidity",
key=SensorKeys.EXTERNAL_HUMIDITY,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
Expand All @@ -322,7 +345,7 @@ def __get_next_mode_change_timestamp(
get_value_fn=__get_value_fn_sensor_value_default,
),
SensorType.EXTERNAL_VPD: ACInfinitySensorSensorEntityDescription(
key="externalVaporPressureDeficit",
key=SensorKeys.EXTERNAL_VPD,
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
suggested_unit_of_measurement=UnitOfPressure.KPA,
Expand All @@ -333,7 +356,7 @@ def __get_next_mode_change_timestamp(
get_value_fn=__get_value_fn_sensor_value_default,
),
SensorType.CO2: ACInfinitySensorSensorEntityDescription(
key="co2Sensor",
key=SensorKeys.CO2_SENSOR,
device_class=SensorDeviceClass.CO2,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
Expand All @@ -344,7 +367,7 @@ def __get_next_mode_change_timestamp(
get_value_fn=__get_value_fn_sensor_value_default,
),
SensorType.LIGHT: ACInfinitySensorSensorEntityDescription(
key="lightSensor",
key=SensorKeys.LIGHT_SENSOR,
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=LIGHT_LUX,
Expand Down Expand Up @@ -470,9 +493,16 @@ async def async_setup_entry(
entities.append_if_suitable(entity)

for sensor in controller.sensors:
description = SENSOR_DESCRIPTIONS[sensor.sensor_type]
entity = ACInfinitySensorSensorEntity(coordinator, description, sensor)
entities.append_if_suitable(entity)
if sensor.sensor_type in SENSOR_DESCRIPTIONS:
description = SENSOR_DESCRIPTIONS[sensor.sensor_type]
entity = ACInfinitySensorSensorEntity(coordinator, description, sensor)
entities.append_if_suitable(entity)
else:
logging.warning(
'Unknown sensor type "%s". Please fill out an issue at %s with this error message.',
sensor.sensor_type,
ISSUE_URL,
)

for port in controller.ports:
for description in PORT_DESCRIPTIONS:
Expand Down

0 comments on commit 15b6774

Please sign in to comment.