Skip to content

Commit

Permalink
fix issue with select controls
Browse files Browse the repository at this point in the history
The response from AC Infinity API can contain None values for fields that expect an enum integer value, resulting in an invalid enum lookup.  Fixes the getters so that they account for a default value if None is encountered.
  • Loading branch information
dalinicus committed Nov 3, 2024
1 parent b259f46 commit 1f47005
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ This integration is compatible with the following UIS Controllers
- Controller 69 Pro
- Controller 69 Pro+

This integration requires the controller be connected to Wifi, and thus is not compatible with bluetooth only devices such as Controller 67 or the base model of Controller 69, as they do not sync directly to the UIS Cloud
This integration requires the controller be connected to Wi-fi, and thus is not compatible with bluetooth only devices such as Controller 67 or the base model of Controller 69, as they do not sync directly to the UIS Cloud

# Installation

## HACS

This integration is made available through the Home Assistant Community Store default feed. Simply search for "AC Infinity" and install it directly from HACS.

![HACS-Instal](/images/hacs-install.png)
![HACS-Install](/images/hacs-install.png)

Please see the [official HACS documentation](https://hacs.xyz) for information on how to install and use HACS.

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ac_infinity/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/dalinicus/homeassistant-acinfinity",
"requirements": [],
"version": "1.7.0"
"version": "1.8.0"
}
13 changes: 8 additions & 5 deletions custom_components/ac_infinity/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def __get_value_fn_outside_climate(
):
return OUTSIDE_CLIMATE_OPTIONS[
entity.ac_infinity.get_controller_setting(
controller.device_id,
entity.entity_description.key,
controller.device_id, entity.entity_description.key, 0
)
]

Expand All @@ -105,7 +104,7 @@ def __set_value_fn_outside_climate(
def __get_value_fn_setting_mode(entity: ACInfinityEntity, port: ACInfinityPort):
return SETTINGS_MODE_OPTIONS[
entity.ac_infinity.get_port_control(
port.controller.device_id, port.port_index, entity.entity_description.key
port.controller.device_id, port.port_index, entity.entity_description.key, 0
)
]

Expand All @@ -125,7 +124,7 @@ def __get_value_fn_active_mode(entity: ACInfinityEntity, port: ACInfinityPort):
return MODE_OPTIONS[
# data is 1 based. Adjust to 0 based enum by subtracting 1
entity.ac_infinity.get_port_control(
port.controller.device_id, port.port_index, PortControlKey.AT_TYPE
port.controller.device_id, port.port_index, PortControlKey.AT_TYPE, 1
)
- 1
]
Expand All @@ -151,6 +150,7 @@ def __get_value_fn_dynamic_response_type(
port.controller.device_id,
port.port_index,
AdvancedSettingsKey.DYNAMIC_RESPONSE_TYPE,
0,
)
]

Expand All @@ -168,7 +168,10 @@ def __set_value_fn_dynamic_response_type(

def __get_value_fn_device_load_type(entity: ACInfinityEntity, port: ACInfinityPort):
value = entity.ac_infinity.get_port_setting(
port.controller.device_id, port.port_index, AdvancedSettingsKey.DEVICE_LOAD_TYPE
port.controller.device_id,
port.port_index,
AdvancedSettingsKey.DEVICE_LOAD_TYPE,
1,
)

return DEVICE_LOAD_TYPE_OPTIONS.get(value, "Unknown Device Type")
Expand Down
6 changes: 5 additions & 1 deletion tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def test_async_setup_mode_created_for_each_port(

@pytest.mark.parametrize(
"value,expected",
[(0, "Neutral"), (1, "Lower"), (2, "Higher")],
[(None, "Neutral"), (0, "Neutral"), (1, "Lower"), (2, "Higher")],
)
@pytest.mark.parametrize(
"setting",
Expand Down Expand Up @@ -157,6 +157,7 @@ async def test_async_set_native_value_outside_climate(
@pytest.mark.parametrize(
"at_type,expected",
[
(None, "Off"),
(1, "Off"),
(2, "On"),
(3, "Auto"),
Expand Down Expand Up @@ -230,6 +231,7 @@ async def test_async_set_native_value_at_type(
@pytest.mark.parametrize(
"value,expected",
[
(None, "Transition"),
(0, "Transition"),
(1, "Buffer"),
],
Expand Down Expand Up @@ -291,6 +293,7 @@ async def test_async_set_native_value_dynamic_response(
@pytest.mark.parametrize(
"load_type,expected",
[
(None, "Grow Light"),
(1, "Grow Light"),
(2, "Humidifier"),
(3, "Unknown Device Type"),
Expand Down Expand Up @@ -381,6 +384,7 @@ async def test_async_set_native_value_load_type_unknown_device_type(
@pytest.mark.parametrize(
"setting_mode,expected",
[
(None, "Auto"),
(0, "Auto"),
(1, "Target"),
],
Expand Down

0 comments on commit 1f47005

Please sign in to comment.