jaroschek / home-assistant-myuplink

Custom Home Assistant integration for devices and sensors in myUplink account.
39 stars 8 forks source link

F730: Increased fan and Temporary Lux are select "on, off" rather than switches #77

Closed grumlu closed 5 months ago

grumlu commented 5 months ago

On my F730, I can control two options: Increased fan speed and Temporary lux (for the temperature water)

These are reported by the integration as select type of entity rather than switch, although the only possible values are "on" and "off". This results in displaying two switches in HomeKit rather than a toggle switch.

I'll try to use a template to convert the value, however it'd be a great addition if the integration was directly proposing a switch.

jaroschek commented 5 months ago

Hello, can you provide the response JSON for the parameter(s) from the swagger site?

The following code line should provide the entity as switch, if there are only these two options and the parameter is writable: https://github.com/jaroschek/home-assistant-myuplink/blob/3efdc319abe661d150652f63ca4802fb30e02055/custom_components/myuplink/api.py#L157-L175

But as I see now, the order of the values seems to be fixed and should be flexible. May be your parameter values are provided in different order?

grumlu commented 5 months ago

Here is the parameters concerning the Increased Ventilation for my device from the swagger site:

 {
    "category": "NIBEF F730 R 1x230V",
    "parameterId": "50005",
    "parameterName": "In­creased venti­lation",
    "parameterUnit": "",
    "writable": true,
    "timestamp": "2024-01-25T19:41:21+00:00",
    "value": 0,
    "strVal": "off",
    "smartHomeCategories": [],
    "minValue": null,
    "maxValue": null,
    "stepValue": 1,
    "enumValues": [
      {
        "value": "0",
        "text": "off",
        "icon": ""
      },
      {
        "value": "1",
        "text": "on",
        "icon": ""
      }
    ],
    "scaleValue": "1",
    "zoneId": null
  }

Could the issue be the casing? I have no upper case for "on" and "off"

jaroschek commented 5 months ago

Unfortunately I did not test your contribution and created the release 1.1.5.

But updating to it revealed, that the proposed code change did not work because of lower(...) being not defined:

2024-01-26 04:33:01.075 ERROR (MainThread) [homeassistant.components.number] Error while setting up myuplink platform for number
Traceback (most recent call last):
  File "/workspaces/home-assistant-core/homeassistant/helpers/entity_platform.py", line 326, in _async_setup_platform
    await asyncio.shield(task)
  File "/workspaces/home-assistant-core/config/custom_components/myuplink/number.py", line 30, in async_setup_entry
    if parameter.find_fitting_entity() == Platform.NUMBER:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/home-assistant-core/config/custom_components/myuplink/api.py", line 163, in find_fitting_entity
    and lower(self.enum_values[0]["text"]) == "off"
        ^^^^^
NameError: name 'lower' is not defined

So I made an additional fix for that by using .lower() instead and published the release 1.1.6 to fix this issue.

grumlu commented 5 months ago

Well, that is embarrassing.

I foolishly thought the validation would see any error with a test dataset or something (I was more afraid of NoneType exceptions), but I clearly should have At least made a code snippet.

In any case, I confirm your update fixed my issue.

Thanks a lot