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

Twinkly integration crashes when tree is not in movie mode #133759

Open
Eising opened this issue Dec 21, 2024 · 4 comments
Open

Twinkly integration crashes when tree is not in movie mode #133759

Eising opened this issue Dec 21, 2024 · 4 comments

Comments

@Eising
Copy link

Eising commented Dec 21, 2024

The problem

I believe have discovered an issue with the twinkly integration. There are a few issues already reported with this similar symptoms, and I believe that these may very well be caused by this issue.

The root cause of the issue is that the Twinkly lights operate in two modes: static, and movie, but the integration always assumes that the movie mode is active.

In the static mode, all LEDs display a single color, whereas in movie mode, the LEDs are used a bit like a screen to display an animation.

There are two issues at play:

Primarily, the hass integration seems to assume that the Twinkly LEDs are always in movie mode.

When the integration runs the async_update method to query the device, it will eventually call the method async_update_current_movie(), which uses the ttls API function get_current_movie().

If no movie is playing, this API will throw an exception which is the second issue.

So for this integration, you could probably run that integration in a try/except block, but it's probably much better to check if it's actually in movie mode.

This is trivial with the API. Here's an example:

async def get_mode(host: str):
    """Resolve the current mode."""
    client = Twinkly(host=host)
    mode = await client.get_mode()
    logger.info(f"Mode: {mode !r}")
    current_mode = mode.get("mode")
    if current_mode == "color":
        print("I'm in static mode!")
    elif current_mode == "rt":
        print("I'm in RT mode.")
    await client.close()

In fact, it would be cool to build upon this static mode and make it work a little like a regular light bulb when in static mode.

Anyway, the problem that most people who can't get this integration to work run in to, is what I just documented here.

I hope you can get a fix ready before Christmas :)

What version of Home Assistant Core has the issue?

core-2024.12.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

twinkly

Link to integration documentation on our website

https://www.home-assistant.io/integrations/twinkly

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-12-21 22:52:55.226 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.XXXXXXX fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 960, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1318, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/twinkly/light.py", line 280, in async_update
    await self.async_update_current_movie()
  File "/usr/src/homeassistant/homeassistant/components/twinkly/light.py", line 306, in async_update_current_movie
    current_movie = await self._client.get_current_movie()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ttls/client.py", line 478, in get_current_movie
    return self._valid_response(await self._get("movies/current"))
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ttls/client.py", line 527, in _valid_response
    raise TwinklyError(f"Invalid response from Twinkly: {response}")
ttls.client.TwinklyError: Invalid response from Twinkly: None

Additional information

EDIT at 2024-12-22: I was some what incorrect in my mode mapping. The rt mode is not the movie mode. It's just called movie.

@home-assistant
Copy link

Hey there @dr1rrb, @RobBie1221, @Olen, mind taking a look at this issue as it has been labeled with an integration (twinkly) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of twinkly can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign twinkly Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


twinkly documentation
twinkly source
(message by IssueLinks)

@Olen
Copy link
Contributor

Olen commented Dec 22, 2024

If I remember correctly, there should be some handling of this. At least I remember some discussions where we realised that setting a single color acted just like setting a movie with a single color playing forever.
And that handling the different modes would just complicate a lot of things.

@Olen
Copy link
Contributor

Olen commented Dec 22, 2024

We are setting mode to movie explicitly here

await self._client.set_mode("movie")

@Eising
Copy link
Author

Eising commented Dec 22, 2024

So, in my case this happened with quite a new setup, and I seem to catch the same kind of situation from some of the other issues on this.

Some posters suggest that setting an effect in the Twinkly app makes home assistant suddenly catch up, so there's definitively something going on here.

I suspect that there is some sort of state in the twinkly controller that makes it unable to just switch to movie mode without any other parameters.

Maybe it's what happens if no movies are available?

According to the REST API documentation, the 1102 error code is just a generic error, so it's impossible to say...

This seems to be exactly what happened to me too. I've had a movie playing for a couple of hours, and the integration started working all of a sudden.

If it wasn't so close to Christmas, I'd reset the whole thing and work on reproducing the issue reliably.

For the integration itself, I would kindly suggest having some check on whether any movies are returned, and if not, operating it in color mode only, avoiding to switch to movie mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants