labthings / labthings/labthings-fastapi

Observable functional properties

Open
#404 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
Currently data properties are observable but functional properties are not. This is annoying when it would be useful to get websocket updates about functional properties. See OFM#883.

Describe the solution you'd like
I think there are two ways to address this, both of which have their place:

  • Allow functional properties to be marked as observable, but rely on the Thing to manually notify their changes. LabThings would be responsible for handling pub/sub logic and generating the Thing Desciption, but would not actually generate notifications: that would need to be instigated manually by the Thing. This would probably be more feasible if data properties could have side effects (#331).
  • Introduce computed properties. Most reactive frameworks provide some sort of computed property. This would allow a new Property to be defined that's a function of other Properties. LabThings would then be able to keep track of which properties might change a computed property, and recompute it when they change.

I think the first option has its place, and is in fact already possible with existing internals. However, I would like to be quite careful about how it's exposed, because there's potential for a lot of confusion if the feature is used incorrectly. I also think LabThings could be much more helpful in most cases.

I think computed properties might not be that bad to implement, and it's worth testing out the idea. I think the tricky bit is how to avoid strange behaviour (e.g. reading things that are not observable, or having side-effects). Most reactive frameworks I've seen will just go wrong if you do naughty things in computed properties, so we probably needn't be too restrictive - but I think the whole thing does work much more elegantly if LabThings can keep track of which attributes are being accessed.

A sensible place to start with computed properties would be to allow a computed property to depend on data properties and computed properties of the same Thing. This could then be extended to allow Thing Slots to be used as well. I think the easiest implementation would be a thin wrapper around self so we can track attribute access.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing property and Thing internals referenced in the issue, comparing manual observable notifications with the proposed computed-property approach. Define how dependencies among data and computed properties would be tracked, then validate that recomputation and websocket notifications behave correctly without unintended side effects.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.