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

Malformed entity id. Broken get_state API #47

Closed
bramstroker opened this issue Nov 5, 2021 · 11 comments · Fixed by #78
Closed

Malformed entity id. Broken get_state API #47

bramstroker opened this issue Nov 5, 2021 · 11 comments · Fixed by #78
Assignees
Labels
bug Something isn't working

Comments

@bramstroker
Copy link

bramstroker commented Nov 5, 2021

Calling get_state will always result in a malformed entity_id error.

state = self.client.get_state(self._entity_id)
File "/usr/local/lib/python3.8/site-packages/homeassistant_api/client.py", line 207, in get_state
raise MalformedInputError(f"The entity_id, {entity_id!r}, is malformed")
homeassistant_api.errors.MalformedInputError: The entity_id, 'light.amirlight', is malformed

I have pinpointed the problem to be in the malformed_id function. https://github.com/GrandMoff100/HomeAssistantAPI/blob/master/homeassistant_api/client.py#L123

The 4th check here entity_id.lower() == entity_id will always evaluate to True, causing the malformed checker to return True.
This should be entity_id.lower() != entity_id imo.

The bug must be introduced in the latest version as it was working fine for me before.

@GrandMoff100
Copy link
Owner

Oh, lol!

Time for post version 2
I also wanna see who changed this lol.

Thanks for informing me about this!

@GrandMoff100
Copy link
Owner

New release coming in a few minutes.

@GrandMoff100
Copy link
Owner

Fixed in version 2.4.0.post2! 🎉

@bramstroker
Copy link
Author

Thanks for the quick resolution. Working fine now!

@alin23
Copy link

alin23 commented Mar 2, 2022

@GrandMoff100
Copy link
Owner

Interesting

@alin23
Copy link

alin23 commented Mar 2, 2022

It's easy to miss something like this in a large diff created by linting/formatting :)

@GrandMoff100
Copy link
Owner

Oh whoops, this is a valid issue. And seeing as I don't think this function is implemented anywhere that why I think this has gone unnoticed. But luckily I think I know just the spot to implement that function!

I should have this fixed in a few minutes.

@GrandMoff100 GrandMoff100 reopened this Mar 2, 2022
@alin23
Copy link

alin23 commented Mar 2, 2022

Maybe it's better to just .lower() the entity_id forcefully for passing it to the API, instead of throwing an error. It would make for a better user experience even for less experienced devs that aren't aware of the casing requirements

@GrandMoff100
Copy link
Owner

Good idea.

@GrandMoff100
Copy link
Owner

Maybe it would also be a good idea to add entity_id structure to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants