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

Service registration #23

Open
zoe-codez opened this issue Aug 8, 2024 · 3 comments
Open

Service registration #23

zoe-codez opened this issue Aug 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@zoe-codez
Copy link
Member

zoe-codez commented Aug 8, 2024

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 buttons

Some chatgpt proof of concept to visualize python side.

from homeassistant.helpers import config_validation as cv
import voluptuous as vol

async def handle_service_call(call):
    # Handle the service call here
    service_data = call.data
    # Example: service_data might include parameters passed to the service

async def async_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 service
    hass.services.async_register(
        domain='your_domain',
        service='your_service',
        service_func=handle_service_call,
        schema=service_schema,
        description=service_description
    )

    return True

Blocked by Digital-Alchemy-TS/hass#34

@zoe-codez zoe-codez added the enhancement New feature or request label Aug 8, 2024
@zoe-codez
Copy link
Member Author

zoe-codez commented Aug 8, 2024

Needs consideration for

@zoe-codez
Copy link
Member Author

zoe-codez commented Sep 9, 2024

Schema

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

@zoe-codez
Copy link
Member Author

How to handle conflicts

Maybe an expansion issue here. Seems like v1 should allow some foot gun and allow conflicts

A follow up might have apps that are conflict-y emit some warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant