Skip to content

Commit

Permalink
add support for controller ai
Browse files Browse the repository at this point in the history
includes the sensor to create sensor entities if they exist.
  • Loading branch information
dalinicus committed Jan 27, 2025
1 parent 05ed982 commit 64526a2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
---
***January 2nd 2025***

***Unfortunetly, the integration does not currently support the recently released AI Controller. I have an AI controller coming, but was delayed due to how AC Infinity bundles multiple pre-orders. I should receive it sometime this January, at which point I'll start working on support ASAP***
***Unfortunately, the integration does not currently support the recently released AI Controller. I have an AI controller coming, but was delayed due to how AC Infinity bundles multiple pre-orders. I should receive it sometime this January, at which point I'll start working on support ASAP***

***If you'd like to join the discussion, please use [Issue #88](https://github.com/dalinicus/homeassistant-acinfinity/issues/88)***

Expand Down
24 changes: 12 additions & 12 deletions custom_components/ac_infinity/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ def __init__(self, controller_json: dict[str, Any]) -> None:
]
]

self._device_info = DeviceInfo(
identifiers={self._identifier},
name=self._device_name,
manufacturer=MANUFACTURER,
hw_version=controller_json[ControllerPropertyKey.HW_VERSION],
sw_version=controller_json[ControllerPropertyKey.SW_VERSION],
model=self.__get_device_model_by_device_type(
controller_json[ControllerPropertyKey.DEVICE_TYPE]
),
)

# controller AI will have a sensor array.
self._sensors = (
[
Expand All @@ -72,17 +83,6 @@ def __init__(self, controller_json: dict[str, Any]) -> None:
else []
)

self._device_info = DeviceInfo(
identifiers={self._identifier},
name=self._device_name,
manufacturer=MANUFACTURER,
hw_version=controller_json[ControllerPropertyKey.HW_VERSION],
sw_version=controller_json[ControllerPropertyKey.SW_VERSION],
model=self.__get_device_model_by_device_type(
controller_json[ControllerPropertyKey.DEVICE_TYPE]
),
)

@property
def device_id(self) -> str:
"""The unique identifier of the UIS Controller"""
Expand Down Expand Up @@ -210,7 +210,7 @@ def sensor_port(self) -> int:
@property
def sensor_type(self) -> int:
"""The type of sensor plugged into the USB-C sensor port"""
return self._sensor_port
return self._sensor_type

@property
def device_info(self) -> DeviceInfo:
Expand Down
44 changes: 20 additions & 24 deletions custom_components/ac_infinity/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
class ACInfinitySensorEntityDescription(SensorEntityDescription):
"""Describes ACInfinity Number Sensor Entities."""

key: str
icon: str | None
translation_key: str | None
device_class: SensorDeviceClass | None
Expand All @@ -69,6 +68,8 @@ class ACInfinityControllerSensorEntityDescription(
):
"""Describes ACInfinity Controller Sensor Entities."""

key: str


@dataclass
class ACInfinitySensorSensorEntityDescription(
Expand All @@ -83,6 +84,8 @@ class ACInfinityPortSensorEntityDescription(
):
"""Describes ACInfinity Device Sensor Entities."""

key: str


def __suitable_fn_controller_property_default(
entity: ACInfinityEntity, controller: ACInfinityController
Expand Down Expand Up @@ -125,7 +128,8 @@ def __get_value_fn_sensor_value_default(
0,
)

return data / (10 * (precision - 1)) if precision > 1 else data
# if statement prevents floating point numbers for integer data in the UI
return data / (10 ** (precision - 1)) if precision > 1 else data


def __suitable_fn_sensor_temperature(
Expand Down Expand Up @@ -180,7 +184,7 @@ def __get_value_fn_sensor_value_temperature(
0,
)

value = data / (10 * (precision - 1)) if precision > 1 else data
value = data / (10 ** (precision - 1)) if precision > 1 else data
return value if unit > 0 else round((5 * (value - 32) / 9), precision - 1)


Expand Down Expand Up @@ -263,9 +267,8 @@ def __get_next_mode_change_timestamp(
),
]

SENSOR_DESCRIPTIONS: list[ACInfinitySensorSensorEntityDescription] = [
ACInfinitySensorSensorEntityDescription(
key=SensorType.PROBE_TEMPERATURE,
SENSOR_DESCRIPTIONS: dict[int, ACInfinitySensorSensorEntityDescription] = {
SensorType.PROBE_TEMPERATURE: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand All @@ -275,8 +278,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_temperature,
get_value_fn=__get_value_fn_sensor_value_temperature,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.PROBE_HUMIDITY,
SensorType.PROBE_HUMIDITY: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
Expand All @@ -286,8 +288,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.PROBE_VPD,
SensorType.PROBE_VPD: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
suggested_unit_of_measurement=UnitOfPressure.KPA,
Expand All @@ -297,8 +298,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.EXTERNAL_TEMPERATURE,
SensorType.EXTERNAL_TEMPERATURE: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand All @@ -308,8 +308,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_temperature,
get_value_fn=__get_value_fn_sensor_value_temperature,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.EXTERNAL_HUMIDITY,
SensorType.EXTERNAL_HUMIDITY: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
Expand All @@ -319,8 +318,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.EXTERNAL_VPD,
SensorType.EXTERNAL_VPD: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
suggested_unit_of_measurement=UnitOfPressure.KPA,
Expand All @@ -330,8 +328,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.CO2,
SensorType.CO2: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.CO2,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
Expand All @@ -341,8 +338,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
ACInfinitySensorSensorEntityDescription(
key=SensorType.LIGHT,
SensorType.LIGHT: ACInfinitySensorSensorEntityDescription(
device_class=SensorDeviceClass.ILLUMINANCE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=LIGHT_LUX,
Expand All @@ -352,7 +348,7 @@ def __get_next_mode_change_timestamp(
suitable_fn=__suitable_fn_sensor_default,
get_value_fn=__get_value_fn_sensor_value_default,
),
]
}

PORT_DESCRIPTIONS: list[ACInfinityPortSensorEntityDescription] = [
ACInfinityPortSensorEntityDescription(
Expand Down Expand Up @@ -468,9 +464,9 @@ async def async_setup_entry(
entities.append_if_suitable(entity)

for sensor in controller.sensors:
for description in SENSOR_DESCRIPTIONS:
entity = ACInfinitySensorSensorEntity(coordinator, description, sensor)
entities.append_if_suitable(entity)
description = SENSOR_DESCRIPTIONS[sensor.sensor_type]
entity = ACInfinitySensorSensorEntity(coordinator, description, sensor)
entities.append_if_suitable(entity)

for port in controller.ports:
for description in PORT_DESCRIPTIONS:
Expand Down
18 changes: 18 additions & 0 deletions custom_components/ac_infinity/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@
"vapor_pressure_deficit": {
"name": "VPD"
},
"probe_temperature": {
"name": "Probe Temperature"
},
"probe_humidity": {
"name": "Probe Humidity"
},
"probe_vapor_pressure_deficit": {
"name": "Probe VPD"
},
"external_temperature": {
"name": "External Temperature"
},
"external_humidity": {
"name": "External Humidity"
},
"external_vapor_pressure_deficit": {
"name": "External VPD"
},
"current_power": {
"name": "Current Power"
},
Expand Down
18 changes: 18 additions & 0 deletions custom_components/ac_infinity/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@
"vapor_pressure_deficit": {
"name": "VPD"
},
"probe_temperature": {
"name": "Probe Temperature"
},
"probe_humidity": {
"name": "Probe Humidity"
},
"probe_vapor_pressure_deficit": {
"name": "Probe VPD"
},
"external_temperature": {
"name": "External Temperature"
},
"external_humidity": {
"name": "External Humidity"
},
"external_vapor_pressure_deficit": {
"name": "External VPD"
},
"current_power": {
"name": "Current Power"
},
Expand Down

0 comments on commit 64526a2

Please sign in to comment.