twrecked / hass-virtual

Virtual Components for Home Assistant
GNU General Public License v3.0
167 stars 28 forks source link

0.9.x - Set available #97

Closed Tony763 closed 9 months ago

Tony763 commented 9 months ago

Hi @twrecked, I am unable to set availability of entity trough websocket. This worked in 0.6.x.

2024-02-04 17:42:08.895 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546918702784] l component not set up
Traceback (most recent call last):
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/components/websocket_api/commands.py", line 238, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2149, in async_call
response_data = await coro
^^^^^^^^^^
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2186, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 1043, in check_permissions
return await service_handler(call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/virtual/__init__.py", line 142, in async_virtual_service_set_available
await async_virtual_set_availability_service(hass, call)
File "/home/homeassistant/.homeassistant/custom_components/virtual/__init__.py", line 206, in async_virtual_set_availability_service
get_entity_from_domain(hass, domain, entity_id).set_available(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/virtual/__init__.py", line 187, in get_entity_from_domain
raise HomeAssistantError("{} component not set up".format(domain))
homeassistant.exceptions.HomeAssistantError: l component not set up
2024-02-04 17:42:08.918 INFO (MainThread) [custom_components.virtual] set_available service called
2024-02-04 17:42:08.918 INFO (MainThread) [custom_components.virtual] s set_avilable(value=False)
2024-02-04 17:42:08.918 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546918702784] s component not set up
Traceback (most recent call last):
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/components/websocket_api/commands.py", line 238, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2149, in async_call
response_data = await coro
^^^^^^^^^^
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/core.py", line 2186, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha/venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 1043, in check_permissions
return await service_handler(call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/virtual/__init__.py", line 142, in async_virtual_service_set_available
await async_virtual_set_availability_service(hass, call)
File "/home/homeassistant/.homeassistant/custom_components/virtual/__init__.py", line 206, in async_virtual_set_availability_service
get_entity_from_domain(hass, domain, entity_id).set_available(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/virtual/__init__.py", line 187, in get_entity_from_domain
raise HomeAssistantError("{} component not set up".format(domain))
homeassistant.exceptions.HomeAssistantError: s component not set up

image

Example websocket payload:

snd = {
  "id": id_msg,
  "type": "call_service",
  "domain": "virtual",
  "service": "set_available",
  "service_data": {
  "entity_id": id_,
  "value": event["state"]
  }
}
Tony763 commented 9 months ago

Syntax for set_available changed:

This works:

 snd = {
  "id": id_msg,
  "type": "call_service",
  "domain": "virtual",
  "service": "set_available",
  "service_data": {
  "value": event["state"]
  },
  "target": {
      "entity_id": id_
  }
}
Tony763 commented 9 months ago

This error occur not just with websocket, I can simulate it inside Developer tools > Services

Firing empty service shows request to define entity_id, device_id or area_id in target or data. image

Adding entity _id inside target works as expected: image

But adding entity _id inside data as suggested by HA fail with error from above: image (b is probably first letter from binary_sensor.aqua_bdoor)

twrecked commented 9 months ago

I had to change some stuff around to make the UI Mode work. I'll take another look.

twrecked commented 9 months ago

I'll fix it. I need to check if entity_id is a list or not.

twrecked commented 9 months ago

Should be fixed by #98 and it's in the latest Alpha.

I had actually forgot to specify a schema for the service.

Let me know if it works for you.

Tony763 commented 9 months ago

Yes, this works. Thank You :slightly_smiling_face: