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 basic support for IKEA Fyrtur blinds #26659

Merged
merged 10 commits into from Sep 22, 2019
Merged

Add basic support for IKEA Fyrtur blinds #26659

merged 10 commits into from Sep 22, 2019

Conversation

ggravlingen
Copy link
Contributor

@ggravlingen ggravlingen commented Sep 15, 2019

Description:

This PR adds basic support for the IKEA Fyrtur window blinds.

Caveat: I don't have one myself, so I need to find someone to test the code. I suggest this to be done before reviewing the code.

Related issue (if applicable): fixes #

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#10373

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@project-bot project-bot bot added this to Needs review in Dev Sep 15, 2019
@MartinHjelmare MartinHjelmare moved this from Needs review to Incoming in Dev Sep 15, 2019

_LOGGER = logging.getLogger(__name__)

IKEA = "IKEA of Sweden"
Copy link
Member

Choose a reason for hiding this comment

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

We use the IKEA constant in many platforms. We can move it to const.py in the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, looking more closely at it, I'm not sure it's being used at all. I'll remove it from all files.


def set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to check for this. It's validated by the service schema already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, removed it.

@callback
def _async_start_observe(self, exc=None):
"""Start observation of cover."""
from pytradfri.error import PytradfriError
Copy link
Member

Choose a reason for hiding this comment

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

Please move 3rd party imports to the top of the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and changed in all files.

Dev automation moved this from Incoming to Review in progress Sep 15, 2019
@ggravlingen
Copy link
Contributor Author

I've posted in the HA forums where adding support has been requested for and asked for someone to do a test against a real blind.

@MartinHjelmare
Copy link
Member

Make sure to run black from the project root.
https://developers.home-assistant.io/blog/2019/07/31/black.html

black --fast homeassistant

@ggravlingen
Copy link
Contributor Author

Thanks, I have a sneaking feeling there was something I'd forgotten in the process! Mind if I add a link to that blog post to the development checklist?

@robbinonline
Copy link

How can I test this?

@ggravlingen
Copy link
Contributor Author

@robbinonline: clone my branch, run the docker script and start HASS. Pair the gateway as usual and the blind should be there.

@robbinonline
Copy link

Hmm that sounds like a big project. Not possible to install it like a custom component or update the changed files?

@ggravlingen
Copy link
Contributor Author

I’m afraid I don’t know how that works. You need to update pytradfri to 6.3.0 and add a file to the tradfri folder but if that is possible as a custom component is beyond me.

The dockerfile ia dockerfile.dev (in my repo, not the official one) if you feel adventurous.

@robbinonline
Copy link

I have updated pytradfri to 6.3.0 and change .coveragerc and add cover.py. Do I also need the other files for the blinds?

@ggravlingen
Copy link
Contributor Author

No, only cover.py.

@ggravlingen
Copy link
Contributor Author

@robbinonline woke up this morning realizing I’ve forgotten to change one file. 🤦‍♂️ Will fix and post here when done.

@robbinonline
Copy link

Ah thats hopefully the reason its not working here, try it for hours yesterday 😅

@ggravlingen
Copy link
Contributor Author

Really sorry about that 🙈 Its been a while since I last built something för HA.

@robbinonline
Copy link

Really appreciate it, looking forward to the updated code!

@ggravlingen
Copy link
Contributor Author

@robbinonline the forgotten change has been added to the code now. You also need to update the __init__.py file.

@robbinonline
Copy link

robbinonline commented Sep 17, 2019

@ggravlingen Allright update the code, and now the blinds shows up in the Integrations, only with the state: entity not available

Schermafbeelding 2019-09-17 om 11 41 51

Checking the logs:

Error doing job: Task exception was never retrieved
11:35 components/cover/__init__.py (ERROR) - message first occured at 11:35 and shows up 2 times
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 408, in _async_add_entity
    await entity.async_update_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 266, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 300, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/cover/__init__.py", line 211, in state
    closed = self.is_closed
  File "/usr/src/homeassistant/homeassistant/components/cover/__init__.py", line 264, in is_closed
    raise NotImplementedError()
NotImplementedError

Did I miss something?

@ggravlingen
Copy link
Contributor Author

@robbinonline you did nothing wrong at all and this is the reason we're testing 😄 It appears I needed to add a is_closed method. I've done so now but it might still be the case that it's not working and I need to add more methods that are required for the blinds to show up.

@robbinonline
Copy link

Allright, update the cover.py, now the blinds appear :)

Schermafbeelding 2019-09-17 om 15 51 01

But the controls don't work it only reads the state, and only updated the state by example how far are the blinds open after a restart.

"""Return if the cover is closed or not."""
if self.current_cover_position == 0:
return True

Copy link
Member

Choose a reason for hiding this comment

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

Add a return False here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@ggravlingen
Copy link
Contributor Author

ggravlingen commented Sep 17, 2019

@robbinonline that's a bit of progress then that we can track current state :) No errors in the log?

I've also adressed the comment of @MartinHjelmare but don't know if that will do anything to make changing the state work.

@MartinHjelmare sorry about spamming this PR. I can ping you when it's working if you want to turn off notifications for this PR?

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Don't worry about notifying me. I'm happy to see the progress. It's also easier to review small chunks at a time. 👍

homeassistant/components/tradfri/cover.py Outdated Show resolved Hide resolved
@MartinHjelmare
Copy link
Member

Has someone tested the observation method in pytradfri with the blinds?

@ggravlingen
Copy link
Contributor Author

@MartinHjelmare good point, I'll go back to pytradfri to find someone to test. This would have been so much easier if I'd had a blind. :)

@ggravlingen
Copy link
Contributor Author

@MartinHjelmare I made some changes to pytradfri to see if we can fix the error that's starting to pop up with the new gateway firmware (#26673). Hence the version bump to 6.3.1.

@MartinHjelmare
Copy link
Member

It would be better to put the library bump in a separate PR since we then could include it in a patch release since it's potentially a fix for a problem.

@ggravlingen
Copy link
Contributor Author

@MartinHjelmare I agree and I will do so as I reckon it will take a bit longer to sort out observation.

There are a few people who are up and running testing this branch, including a few who experience the bug, so I figured it'd be an easy way of testing to just bump the version here.

@ggravlingen ggravlingen mentioned this pull request Sep 19, 2019
9 tasks
@MartinHjelmare MartinHjelmare moved this from Reviewer approved to Incoming in Dev Sep 19, 2019
@ggravlingen
Copy link
Contributor Author

Argh, I rebased and messed up 🤦‍♂

@ggravlingen
Copy link
Contributor Author

I'll fix this later tonight

@ggravlingen
Copy link
Contributor Author

@MartinHjelmare when you feel the code is in line with HA standards, this one is good to go. I got confirmation on the forums that it works as expected:

image
Source: https://community.home-assistant.io/t/please-add-support-for-blinds-activated-in-the-ikea-integration/137253/38

@ggravlingen ggravlingen changed the title WIP: Add basic support for IKEA Fyrtur blinds Add basic support for IKEA Fyrtur blinds Sep 22, 2019
def __init__(self, cover, api, gateway_id):
"""Initialize a cover."""
self._api = api
self._unique_id = f"cover-{gateway_id}-{cover.id}"
Copy link
Member

Choose a reason for hiding this comment

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

The entity registry is aware of the integration domain and platform domain of the entity, so adding cover isn't necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove it but just a double check as I saw this in light and also noticed who made the change, so I figured it wasn't put there randomly?

image

Copy link
Member

Choose a reason for hiding this comment

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

The light platform has two kinds of entities, light and group. If there are more than one type of entity in a platform and the rest of the id is the same between the two kinds, we need to add a differentiator.

I don't know if this is actually the case for the light platform, ie if group.id and light.id are the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, thanks for the explanation

@MartinHjelmare MartinHjelmare moved this from Incoming to Review in progress in Dev Sep 22, 2019
Dev automation moved this from Review in progress to Reviewer approved Sep 22, 2019
@MartinHjelmare
Copy link
Member

Can be merged when build passes.

@ggravlingen
Copy link
Contributor Author

Thank you for the advice during review and to all the testers 🎉🙏

@MartinHjelmare MartinHjelmare merged commit 49fef9a into home-assistant:dev Sep 22, 2019
Dev automation moved this from Reviewer approved to Done Sep 22, 2019
@lock lock bot locked and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants