-
Notifications
You must be signed in to change notification settings - Fork 570
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
Major refactor of cover platform and config flow support tweaks for cover platform #10
Conversation
Regarding keeping track of opening percentage, I had thought a lot about it and I think it's not a good idea, or at least I would make it optional. This because if you have a cover (like mine) that has also physical buttons (which I believe is the most common situation) there is no way for the device to know if a manual opening or closing has occurred, and for how long. The positioning info is unreliable for these devices, as a consequence. |
Hi @rospogrigio, thanks for the note. I'm curious to see how your device compares to mine. This will help us think of the best way to approach this situation. Can you run the following two scenarios for me: Scenario A
Scenario B
|
OK I'll try it but first I have to fix tuya-cli because it has never worked with my cover devices, but now I should know how to fix it. Edit: no, I actually can't understand how to fix tuya-cli, it goes over my skills. It's the same old "json data unvalid" error, however, that tuyapi still does not handle correctly. |
Hello, I'm using 3 cover switches with the current implementation of local tuya. |
@rospogrigio, I forgot that tuya-cli does not work with your device. Can you get me the output of those 4 scenarios above (A.3, A.7, B.3, B.7) using a different method. Instead of using tuya-cli, let's use localtuya's debug output. In
Then, enable debug logging in
Now, run the 4 scenarios above (A.3, A.7, B.3, B.7), and after each one, wait until the next |
Thank you for this, it's very helpful. As you said, your cover device opens/closes based on a set amount of time. It does not report current position, nor let you set current position. It's entirely time based. That's very different from my device, which does not use timers. Rather, it reports the current position ('3') and lets me set the current position directly ('2').
I think that @rospogrigio's device is similar to yours, as his commands are also However, I want to wait until @rospogrigio provides his output for those 4 scenarios just to be certain. If @rospogrigio's output looks similar to yours, then I think a potential solution is as follows:
@rospogrigio I know you used to have some code for setting an actual position of time-based cover devices, but I am struggling to understand how it works in practice:
Can you explain how this code worked in conjunction with your device. It's confusing to me, because you're setting the (Sidenote, but does calling |
My general thoughts are that if a cover device doesn't technically support setting the position, then we probably shouldn't include a hacked together attempt to set the position. And on that train of thought, if a device does not support setting the position, we should ensure that Those are my thoughts on the matter. @postlund, curious to hear your thoughts (on how we should approach cover devices that don't technically report the current position or let you set the new position). |
I tend to agree with you @andrewmeepos. If we can't provide a reliable position it's better if we don't. The user will know this. Since Home Assistant provides a template for covers, users can toll their own solution: https://www.home-assistant.io/integrations/cover.template/#position_template |
And yeah, we must not return |
please note that the cover device is managing the time by itself. Could be a workaround to finally set position to 50 in order to let the widget always proposing close and open actions as HASS does not know the real position. |
@andrewmeepos , I will try to get the output you need as soon as I can. |
Here is the output: I only get the status (1) and the dps 101, which is the backlight status. I'd leave the behavior configurable, with options Position/Hacked position/None. |
@rospogrigio , I wonder whether the hacked position could be achieved through the template cover, https://www.home-assistant.io/integrations/cover.template/#position_template as suggested by @postlund and script for setting position. But I'm very new to HA and not yet comfortable with these features |
I'm not sure. I might be ok with including "Hacked Position" as an option, as long as we very clearly explain what it is that "Hacked Position" does. However, it is definitely improper Home Assistant behavior. Would we also have to add a configuration option for time to open/close? I'm leaning towards not including it, but I could be convinced either way. I recognize that excluding this option would be unfortunate for those with devices that don't support set position. I have no experience with What do others think? @postlund? |
In my case, the trip-time is at dps 9 and most probably can be set by HA. I guess this can be detected automatically. |
I would like to propose that we proceed with merging this pull request. However, I see that there are conflicts. Can someone explain how I go about resolving these conflicts? I'm a little confused. @rospogrigio, after this is merged you can open a new pull request which adds the functionality to use the "Hacked Position" open, and we can continue the discussion there. |
You can always just "push -f" to your branch to start over. There's really no need to close the PR. |
11108b8
to
79bd720
Compare
@postlund Ok, finally figured out how to rebase and force push. Anyways, the one error holding me up on this is below. I get the error every time I finish setting up a cover device from the config flow. Everything was working prior to merging my code to the latest master, so I must've done something wrong when updating my code. Haven't been able to get to the bottom of this yet.
|
As I wrote in #19, I'm getting the same error so that's not your fault. Will try to fix it when I get the time. |
Do you get this error when setting up switches too, or just covers? |
@postlund I've incorporated most of your changes. I had a few questions about your feedback, which i've added as comments. I have not yet pushed the updated PR, as I want to resolve my several questions with your feedback before doing so. |
@andrewmeepos I think/hope I answered the questions now. |
@postlund Ok, I think I updated everything. Take a look and let me know. |
Would be great to get this merged so I can stop resolving conflicts and/or rebasing over and over 😬 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small things left but otherwise it's good!
@postlund I believe I incorporated all of your comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added two minor things I found after looking at everybody again. After that I'm all for merging 👍
custom_components/localtuya/cover.py
Outdated
def status_updated(self): | ||
"""Device status was updated.""" | ||
self._cached_status = self._status | ||
self._last_movement = self._cached_status['dps'][str(self._config[CONF_LAST_MOVEMENT])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought once more about these. You can use self.dps(...)
to fetch the value (forgot about that one for a second). So basically:
self._last_movement = self.dps(str._config.get(CONF_LAST_MOVEMENT))
This will log a warning if the requested DP does not exist.
@postlund good to merge? |
@andrewmeepos Yeah! 👍 |
@postlund I tested it and it had some issues, but I just fixed it. For the record, this is the line that didn't work: Changed it to this and it works: Just need to fix conflicts with master, remove my internal logging, and push. |
@postlund @rospogrigio ok, this should be good to merge |
Sorry @andrewmeepos but I still could not test this and I must ask you to suspend working on this until we have merged #40 because I would really have that sorted before proceeding, and I don't want to waste your time by having you solve conflicts over and over again. Once #40 is done, I promise this will be the next PR to go in. |
Totally rewritten in #60, closing PR. |
2.1.0 Introduce templates
This is a major rework and refactor of cover.py.
Depends on #6
Should be merged after #8 for the cleanest merging.
See https://github.com/postlund/localtuya-homeassistant/pull/1 for previous conversation with @postlund on this PR.
A few things to note about my pushed code:
This is a a pretty major rework of cover.py. I refactored almost all of the functions to align with Home Assistant best practices for devices generally and for covers specifically, per https://developers.home-assistant.io/docs/core/entity/cover/ and https://developers.home-assistant.io/docs/asyncio_working_with_async/.
None of my "set" functions (open, close, set position, etc.) in cover.py call anything in init.py other than set_value. As rospogrigio mentioned, and with which I completely agree, pytuya should be a minimal library to communicate with Tuya devices. Handling of specific device characteristics, attributes, functions, etc., should be done on localtuya's end.
Here's my lovelace code which shows the blind using a few different card types (some stock, some custom).
And that gets you:
(Note: The reason the top card shows 81% and the bottom card shows 80% is because the bottom card rounds to the nearest 10%).
I need to add code to validate that OPEN_CMD, CLOSE_CMD, and STOP_CMD are all in lowercase ("open" vs "OPEN" or "Open"--only works when all lowercase). Or, alternatively, let people use whatever they want in config and then parse it as lowercase in cover.py. Or both. Easy fix but not a big deal and will do it later.
When you hit one button on the lovelace UI (such as open) and then VERY QUICKLY (within less than a second or so) hit another button (such as stop), the second command sometimes does not register. This might just be a limitation of Tuya devices--they don't like getting inundated with rapid connections.
When you open or close the blind, and then hit stop, the current_cover_position immediately updates to the correct value. However, when you set a specific position, and the cover opens/closes to that position, the current_cover_position does not update until the next update call after the opening or closing is complete, which can be as long as 30 seconds, but is usually closer to 15 seconds.