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
It'd be awesome if synapse was able to expose service calls to home assistant, in addition to entities. This would enable more standard interactions via hass.call, instead of weird side workflows involving buttons
Some chatgpt proof of concept to visualize python side.
fromhomeassistant.helpersimportconfig_validationascvimportvoluptuousasvolasyncdefhandle_service_call(call):
# Handle the service call hereservice_data=call.data# Example: service_data might include parameters passed to the serviceasyncdefasync_setup(hass, config):
service_schema=vol.Schema({
vol.Required('field1'): cv.string,
vol.Optional('field2', default='default_value'): cv.string,
vol.Required('field3'): cv.positive_int,
})
service_description= {
"description": "Description of what this service does",
"fields": {
"field1": {
"description": "Description of field1",
"example": "example_value"
},
"field2": {
"description": "Description of field2",
"example": "example_value"
},
"field3": {
"description": "Description of field3",
"example": 42
}
}
}
# Register the servicehass.services.async_register(
domain='your_domain',
service='your_service',
service_func=handle_service_call,
schema=service_schema,
description=service_description
)
returnTrue
Seems like this might be best approached with something that do validation. class-validator, zod, and the like have the ability to check on the incoming values.
They can also translate to json schema, which can then be handled by vol in python
Not sure what the flavor of the month for validators is tho
Context
It'd be awesome if synapse was able to expose service calls to home assistant, in addition to entities. This would enable more standard interactions via
hass.call
, instead of weird side workflows involving buttonsSome chatgpt proof of concept to visualize python side.
Blocked by Digital-Alchemy-TS/hass#34
The text was updated successfully, but these errors were encountered: