You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure if the issue is because I have missed something or understood wrong.
I fetching status from one sensor using the HomeAssistant API, and receives "Unclosed client session" when the routine is inside a function. When I use the same code outside the function it works without any additional printouts.
Example when it works:
from homeassistant_api import Client
URL = '<url>'
TOKEN = '<token>'
with Client(
URL,
TOKEN,
) as client:
state = client.get_state(entity_id="sensor.kitchen_motion_sensor_temperature_2")
print(state)
Hi,
I am not sure if the issue is because I have missed something or understood wrong.
I fetching status from one sensor using the HomeAssistant API, and receives "Unclosed client session" when the routine is inside a function. When I use the same code outside the function it works without any additional printouts.
Example when it works:
Result:
$ python3 getstate-v2.py
entity_id='sensor.kitchen_motion_sensor_temperature_2' state='19.8' attributes={'state_class': 'measurement', 'unit_of_measurement': '°C', 'device_class': 'temperature', 'icon': 'mdi:thermometer', 'friendly_name': 'AC Sensor-2 Temperature'} last_changed=datetime.datetime(2022, 11, 6, 12, 31, 8, 698689, tzinfo=datetime.timezone.utc) last_updated=datetime.datetime(2022, 11, 6, 12, 31, 8, 698689, tzinfo=datetime.timezone.utc) context=Context(id='')
$
Example when it output the "Unclosed client session"
Result:
$ python3 getstate-v1.py
The text was updated successfully, but these errors were encountered: