Possible bug in get_state
Closed this issue · 2 comments
MikeColeGuru commented
Describe the bug
I'm trying to get the state object for an entity but I'm getting an error.
Traceback (most recent call last):
File "gettemp.py", line 7, in <module>
therm_state = client.get_state('climate.hallway_thermostat')
TypeError: get_state() takes 1 positional argument but 2 were given
To Reproduce
from homeassistant_api import Client
with Client(
'<api url>',
'<api key>'
) as client:
therm_state = client.get_state('climate.hallway_thermostat')
Expected behavior
State object in therm_state variable
Desktop (please complete the following information):
- OS: Ubuntu 20.04
- HomeAssistant Version: 2022.3.4
- homeassistant-api Version: 3.0.3
MikeColeGuru commented
Note: client.get_states() does work and includes the state that I am requesting above but is slow and takes up resources.
from homeassistant_api import Client
with Client(
'<api url>',
'<api key>'
) as client:
states = client.get_states()
for state in states:
if state.entity_id == 'climate.hallway_thermostat':
print(state)
break
GrandMoff100 commented
Sorry to hear about this!
The method get_state
only accept keyword arguments.
So to fix your bug your code should look like this
from homeassistant_api import Client
with Client(
'<api url>',
'<api key>'
) as client:
therm_state = client.get_state(entity_id='climate.hallway_thermostat')
Or if you wish to supply the entity domain and entity slug sepparately (in your case climate
is the entity domain, and hallway_thermostat
is the entity slug) you can pass group=
and slug=
instead of passing entity_id like this
from homeassistant_api import Client
with Client(
'<api url>',
'<api key>'
) as client:
therm_state = client.get_state(group='climate', slug='hallway_thermostat')