Skip to content

Conversation

@dmcc
Copy link

@dmcc dmcc commented Mar 16, 2025

This is primarily intended for demonstration/discussion purposes. Also my first Home Assistant component PR, so feedback highly welcomed! Related issue: dlarrick/pykumo#51

Is this the API we want? Get/set are pretty low level (which might be fine). With a little work, we could also make it easy to enable/disable a range of schedule slots. With more work, we could make it so that Home Assistant could set all the fields in a single slot.

Note that this doesn't work on its own -- it needs to be used in conjunction an updated version of PyKumo which includes dlarrick/pykumo#53.

Before finalizing:

dmcc added 2 commits March 16, 2025 11:10
This is primarily intended for demonstration/discussion purposes.
Copy link
Owner

@dlarrick dlarrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My basic thought here is that, yeah, it'd be nice to present a higher-level schedule interface, but what you're proposing here is usable if it has good schema validation such that people can figure out what they're doing wrong. Your comment about "intended for advanced use" is a good hint that this is pretty low-level.

For a higher-level schedule interface, I wonder if using or subclassing Schedule would be useful & doable?

schema={
vol.Required("entity_id"): str,
# TODO: This could be a lot tighter...
vol.Required("schedule"): vol.Schema({}, extra=vol.ALLOW_EXTRA),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are online JSON schema generators that will write a JSON schema given an example JSON body. They're not perfect but can generate a good starting point. Or a tool like Swagger can be used to create a JSON schema from scratch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing an endpoint on pykumo to get the schedule schema (and using it here) might be a good way to hide this detail away from hass-kumo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see main comment about when we want to start enforcing the schema) Yeah, I tried a bit to get the schema set (partially just to learn about how Home Assistant handles these things). I ran into confusing issues with voluptuous, but can take another look if you'd like to see this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's not a full schema validation but just code (inside pykumo) checking that required stuff is present and in the expected format, with useful error messages returned if not, that would be something. OTOH that's the sort of thing schema validation is good at. But I haven't played with whatever validator HA is using.

So I guess my preference would be for a somewhat loosely-defined schema that validates just the minimum. I'm thinking just something to protect the code from crashing due to unanticipated values/formats. Later, if you're able to make a higher-level interface in future, it would be different endpoints and so the schema would be different.

@dmcc
Copy link
Author

dmcc commented Mar 23, 2025

My basic thought here is that, yeah, it'd be nice to present a higher-level schedule interface, but what you're proposing here is usable if it has good schema validation such that people can figure out what they're doing wrong. Your comment about "intended for advanced use" is a good hint that this is pretty low-level.

Yeah, that's my thinking as well -- at least for a v1, I think it's fine to include it as an experimental feature. I think we may learn a bit more about what fields/values are accepted and how these are across devices, so not sure if we want to lock down the schema (yet). Let me know what you think.

For a higher-level schedule interface, I wonder if using or subclassing Schedule would be useful & doable?

Ooh, hadn't been following that -- very interesting. It looks like it could work, but it doesn't seem like it matches up exactly with our use cases. Some initial thoughts after playing around with it:

  • One question is what Schedule's "start"/"end" times would translate to since we only have "start" times. I suppose if we specify a default (e.g., "off"), then we could say that any unscheduled time would use that.
  • The current UI for the official Schedule seems a bit tricky to use for these purposes (things like the mode and temperature would need to be specified under "Advanced settings" -> "Additional data" which aren't shown the weekly overview) so it might not end up being less cumbersome than raw YAML.
  • Are there other things we could use on HACS (or elsewhere)? I did some cursory searches but didn't find anything that looked like a great match.

@dlarrick
Copy link
Owner

  • things like the mode and temperature would need to be specified under "Advanced settings" -> "Additional data"

My hope is that a subclass of Schedule could provide additional UI fields and validation. But I have not looked at it at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants