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

Major upgrade #70

Merged
merged 10 commits into from
Dec 8, 2024
Merged

Major upgrade #70

merged 10 commits into from
Dec 8, 2024

Conversation

zoe-codez
Copy link
Member

@zoe-codez zoe-codez commented Dec 3, 2024

📬 Changes

⚠️ REQUIRES UPGRADE TO ADDON

Changes

Default config updates

Previously, setting up an entity like this would cause the icon to be captured in the database, then served up as the real value until the end of time (or you reset the db)

// boot 1
const mySwitch  = synapse.switch({
  icon: "mdi:foo"
})
// ✅ boot 2, value changes
const mySwitch  = synapse.switch({
  icon: "mdi:bar"
})

When a new entity is declared, the default values are compared and the field is reset if a change in default value is detected. As long as the default value is the same, the value inside of the database continues to take priority

mySwitch.icon = "mdi:baz"; // ✅ assignment is tracked in database 

Reactive configs

Full source for example

synapse.sensor<{ locals: { targetTime: string }; state: string }>({
 // condensed notation for when the defaults will work
  icon: ({ locals }) => (locals.targetTime ? "mdi:cookie-clock" : "mdi:cookie-alert-outline"),
  locals: { targetTime: undefined },
  state: {
// expanded notation still valid
    current({ locals }) {
      const now = dayjs();
      const diff = dayjs(locals.targetTime).diff(now, "second");
      const value = Math.max(0, diff).toString();
      return `${value}s`;
    },
    schedule: CronExpression.EVERY_SECOND,
  },
});

All reactive configs receive the proxy as the 1st param. This helps to resolve circular type references (which makes typescript big mad).

Reactive bindings

The current expanded notation for reactive allows for an onUpdate list of entities to influence when the reactive functions are run. Items in the bind array in the entity reference will be merged with that list.

These apply to the condensed function notation also

synapse.sensor<{ locals: { targetTime: string }; state: string }>({
  bind: [hassEntityReference, synapseEntity],
  icon: ({ locals }) => ...
});

🗒️ Checklist

  • Read the contribution guide and accept the
    code of conduct
  • Readme and docs (updated or not needed)
  • Tests (added, updated or not needed)

@zoe-codez zoe-codez changed the title Trace logs Major upgrade Dec 8, 2024
@zoe-codez zoe-codez merged commit 85cd878 into main Dec 8, 2024
3 checks passed
@zoe-codez zoe-codez deleted the trace_logs branch December 8, 2024 21:14
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.

1 participant