Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform support for humidifiers and Rename DPS, and DPS_CONF Functions #47

Merged
merged 9 commits into from
Oct 25, 2023

Conversation

xZetsubou
Copy link
Owner

@xZetsubou xZetsubou commented Oct 25, 2023

Add humidifiers support.
Rename functions:
dps -> dp_value
dps_conf -> dp_value_conf

closes #46

@xZetsubou xZetsubou linked an issue Oct 25, 2023 that may be closed by this pull request
@codyc1515
Copy link

codyc1515 commented Oct 25, 2023

Mostly there! This is causing the switch to be unavailable. Note: like I said before, I do not have a target humidity.

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/humidifier.py:95
Integration: LocalTuya (documentation, issues)
First occurred: 21:00:56 (1 occurrences)
Last logged: 21:00:56

Error doing job: Exception in callback Entity.async_write_ha_state()
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 822, in _async_generate_attributes
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/humidifier/__init__.py", line 186, in state_attributes
    if self.target_humidity is not None:
       ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/humidifier.py", line 95, in target_humidity
    target_dp = self._config.get(self._dp_target, None)
                                 ^^^^^^^^^^^^^^^
AttributeError: 'LocaltuyaHumidifier' object has no attribute '_dp_target'

Less worried about this one.

This error originated from a custom integration.

Logger: custom_components.localtuya.humidifier
Source: custom_components/localtuya/core/pytuya/__init__.py:280
Integration: LocalTuya (documentation, issues)
First occurred: 21:00:56 (2 occurrences)
Last logged: 21:00:56

[eb9...wib] Entity humidifier.diffuser_switch is requesting unset index for option humidifier_current_humidity_dp
[eb9...wib] Entity humidifier.diffuser_switch is requesting unknown DPS index None

@codyc1515
Copy link

codyc1515 commented Oct 25, 2023

Just re-configured the device without that dp_target_humidity set and received a different error.

This error originated from a custom integration.

Logger: custom_components.localtuya.humidifier
Source: custom_components/localtuya/core/pytuya/__init__.py:280
Integration: LocalTuya (documentation, issues)
First occurred: 21:06:09 (24 occurrences)
Last logged: 21:08:47

[eb9...wib] Entity humidifier.diffuser_switch is requesting unset index for option humidifier_current_humidity_dp
[eb9...wib] Entity humidifier.diffuser_switch is requesting unknown DPS index None

... That said, it works! 🎉

image

Copy link

@codyc1515 codyc1515 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is here:

target_dp = self._config.get(self._dp_target, None)

self._dp_target should be self._dp_target_humidity

@xZetsubou
Copy link
Owner Author

xZetsubou commented Oct 25, 2023

Just re-configured the device without that dp_target_humidity set and received a different error

Dose your humidifier doesn't have "humidity temp" sensor? I thought all humidifiers have that.

self._dp_target should be self._dp_target_humidity

I forgot to change that variable 😿 , thanks.

Do you mind sharing a picture of your humidifier DPS: like this

@codyc1515
Copy link

codyc1515 commented Oct 25, 2023

Sorry, I cannot see that screen as the device is fully configured now but happy to share the YAML. The device itself is a Kogan SmarterHome™ 2.8L Humidifier but more realistically is actually a Diffuser. Because of this, no Humidify DP as the device just runs till you turn it off or it runs out of water.

- binary_sensor:
    device_class: problem
    entity_category: diagnostic
    friendly_name: Fault
    icon: ''
    id: '22'
    platform: binary_sensor
    state_on: 'True'
- select:
    entity_category: config
    friendly_name: Timer
    icon: ''
    id: '19'
    is_passive_entity: false
    platform: select
    restore_on_reconnect: false
    select_options: cancel,2h,4h,8h
    select_options_friendly: Off,2h,4h,8h
- number:
    device_class: duration
    entity_category: diagnostic
    friendly_name: Timer Remaining
    icon: ''
    id: '20'
    is_passive_entity: false
    max_value: 480.0
    min_value: 0.0
    platform: number
    restore_on_reconnect: false
    step_size: 1.0
    unit_of_measurement: minutes
- select:
    entity_category: config
    friendly_name: Intensity
    icon: ''
    id: '3'
    is_passive_entity: false
    platform: select
    restore_on_reconnect: false
    select_options: small,middle,large
    select_options_friendly: Low,Medium,High
- switch:
    device_class: switch
    entity_category: config
    friendly_name: Sleep
    icon: ''
    id: '16'
    is_passive_entity: false
    platform: switch
    restore_on_reconnect: false
- light:
    brightness_lower: 29
    brightness_upper: 1000
    color_temp_max_kelvin: 6500
    color_temp_min_kelvin: 2700
    color_temp_reverse: false
    entity_category: config
    friendly_name: Light
    icon: ''
    id: '5'
    music_mode: false
    platform: light
- humidifier:
    device_class: humidifier
    entity_category: None
    friendly_name: Switch
    id: '1'
    max_humidity: 100
    min_humidity: 0
    platform: humidifier

@xZetsubou
Copy link
Owner Author

xZetsubou commented Oct 25, 2023

The yaml doesn't have the codes of dp ids in that case can you go to your device then download the diagnostic.
I want to double check Auto configure feature for humidifiers ^^

@codyc1515
Copy link

Ah sorry here you go:

1, switch, False
2, switch_spray, False
3, spray_volume, large
5, switch_led, False
16, sleep, False
19, countdown_set, cancel
20, countdown_left, 0
22, fault, 0

@xZetsubou
Copy link
Owner Author

Ah sorry here you go:

I assume the category is: cs ? it should show in diagnostic file as well

@codyc1515
Copy link

codyc1515 commented Oct 25, 2023

On the contrary, "category": "jsq". What is the difference?

"product_id": "w9l8cmqoi50egpam", "product_name": "Humidifier" if that helps too.

Ah just read that jsq = Humidifier. Neat!

@xZetsubou
Copy link
Owner Author

xZetsubou commented Oct 25, 2023

Ah just read that jsq = Humidifier. Neat!

Yeah don't know why did they list it under humidifiers category.
I added humidifier platform on auto configure if you have time free time give it a try, Thanks for the informations.

@codyc1515
Copy link

No problem, I can try it. Let me know when you make the next beta release.

@xZetsubou xZetsubou changed the title Add platform support for humidifiers Add platform support for humidifiers and Rename DPS, and DPS_CONF Functions Oct 25, 2023
@xZetsubou xZetsubou merged commit 644c7dc into rework_subdevices_connect Oct 25, 2023
3 checks passed
@xZetsubou
Copy link
Owner Author

No problem, I can try it. Let me know when you make the next beta release.

https://github.com/xZetsubou/hass-localtuya/releases/tag/3.2.0b16

@codyc1515
Copy link

Looks good to me :)

@xZetsubou xZetsubou deleted the add_humidifier_platform branch October 26, 2023 11:31
xZetsubou added a commit that referenced this pull request Oct 30, 2023
* Rework SubDevices Connection

* Fix some stuff in payload_dict for sub devices `3.3`

* Don't send warning disconnect dc is intended

* Hotfix for `3.3` devices `detect_available_dps`

* Add sensors for code `wsdcg`

* Attempt Fix: some dps aren't detected.

* Adjust `detect_available_dps` Function when gateway existed

* int `t` since sub_devices payload `t` is int

* revert last commit force int `"t"` always, need for some cmds

* test: disable removing the [ gwID, devId and uid ]

* Disconnect the sub devices if gateway dc'd

* ensure that the gateway is ready before setup subdevices

* Fix: Block status_updated if gateway is sub_device

* Add gateway_gwId to discovered sub devices. and prevent non local subdevices

* Store Gateway ID If found on mergeDevicesList

* minor changes of connect on initialization

* config_entry_by_device_id search for gateways

* Minor fix: Rename climates.py in tuya devices data

* Tuya Devices Data rename binary_sensor

* Adjust Auto Configure category `wkf`

* Fix automatic update `ip` and includes sub_devices

* Except errors from pytuya.

* Except error on config flow and set timeout for connect.

* Fix: Entity_Category and convert get_gateway to async

* Fix Mirgate: Force Int for config_flow values and fix reverse always off

* Fix: Fake Gateway fails due to no DPS found on parent DPS.

* reformat unload function.

* Fix Reconfigure cloud step

* Fix error if "Auto Configure" used without cloud.

* Add platform support for humidifiers and Rename DPS, and DPS_CONF Functions (#47)

* Add support for humidifier platform

* Add Humidifer to Auto Configure feature.

* Improve English translations to be more user friendly #45 by @codyc1515

* Adjust `en` translation for humidifer

* mark set_humiditiy as optional

* log the disconnect reason of exists

* Adjust get_gateway function

* adjust error msgs in auto configure

* Refactor: entities initialization msg and remove dp_value_conf (#49)

* Initialized msg to `common.py` and del: `dp_value_conf`

* def should_pull to _attr_should_pull and refactor restore_on_reconnect

* refactor entity category

* Refactor: `device_info` and properties annotation

* Improve entry initialization (#50)

* Connecting `CloudAPI` runs on background without interrupt initialization.

* Unload: pulls platforms from `TuyaDevice` data Explain: #50

* Improves config flow (#51)

* DPS Data now will be pulled with devices data, data stored in `device_id` -> in `devices_list` with `dps_data` key.
* Adding new device DPS Data will be pulled from stored data `except the value!`
* Devices list in config flow now will be sorted: Starting from known devices first.
* Refresh cloud devices data when configure opened. `previously reload was needed in order to pull new devices data.`
* Handle the errors if refreshing token failed.

* Enable manually enter template filename (#52)

* Templates list field are now insertable and searchable, so if you add templates new template into `templates` directory you can manually enter there name without need to load them up with HA boot.
* Templates names now will shows the same as filename with extension.

* update pytuya version

* revert auther name

* Sort discovered devices by `ip`

* Handle sorting discovered devices better

* refactor: devices list sorting

* adjust dc reason log

* refactor: mergeDevicesList

* new helper `get_gateway_by_id` refactor mergeDeivceList

* typo

* * Refactor codes a little bit to make it easier to maintain. (#53)

* * Refactor codes a little bit to make it easier to maintain.
* cloud_api now has async_connect function.
* Localtuya HASS Data is now stored as namedtuple `HassLocalTuyaData`
* Removed `TUYA_DEVICES`, `DATA_CLOUD` and `UNSUB LISTENERS`
* Sotred all unsub_callback in tuya_devices.unsub_listeners
* Reconnect if disconnected will be called after 2secounds.

* Fix reconnect after 2 secounds.

* Hide reconifgured device if no devices setuped (#54)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support humidifier platform
2 participants