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

Types & serialization #32

Merged
merged 22 commits into from
Sep 25, 2024
Merged

Types & serialization #32

merged 22 commits into from
Sep 25, 2024

Conversation

zoe-codez
Copy link
Member

@zoe-codez zoe-codez commented Sep 7, 2024

📬 Changes

General

Added serialization and validation support for setting entity configuration values.
Some properties actually will care about what data they take in / return back now

Date Entities

docs

Allow setting dayjs | date | iso as a native_value type. Anything dayjs can work with is valid, but the timestamp will always be reset to start of day

synapse.date<{ date_type: "dayjs" }>({
    // ...
	date_type: "dayjs"
})

DateTime Entities

docs

Same as date, but no loss of time portion

synapse.datetime<{ date_type: "iso" }>({
    // ...
	date_type: "iso"
})

Select Entities

No functional changes, but added the ability to declare options

synapse.select<{ options: "a" | "b" | "c" }>({
  options: ["a", "b", "c"]
})

Sensor Entities

Sensors may take in a variety of state types now, but which ones actually work will depend on the device_class of the sensor. The type definitions have been adjusted for a lot of the device classes to help better surface the optional (and required) attributes for a specific class

valid state types: dayjs | number | string (unions supported) | date | iso

synapse.sensor<{ state: number }>({
  sensor_type: "number",
  device_class: "aqi"
})

Internals Upgrade

Migrate to new core testing utils, change over to esm, upgrade eslint

🗒️ Checklist

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

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 25.40984% with 91 lines in your changes missing coverage. Please review.

Project coverage is 60.42%. Comparing base (40bc5e1) to head (07a6e44).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/extensions/domains/sensor.extension.ts 19.04% 34 Missing ⚠️
src/extensions/domains/date.extension.ts 16.00% 21 Missing ⚠️
src/extensions/domains/datetime.extension.ts 12.50% 21 Missing ⚠️
src/extensions/generator.extension.ts 61.53% 4 Missing and 1 partial ⚠️
src/extensions/socket.extension.ts 28.57% 5 Missing ⚠️
src/helpers/utility.helper.ts 0.00% 4 Missing ⚠️
src/extensions/domains/select.extension.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #32       +/-   ##
===========================================
- Coverage   83.80%   60.42%   -23.38%     
===========================================
  Files          46       43        -3     
  Lines         636      657       +21     
  Branches       62       88       +26     
===========================================
- Hits          533      397      -136     
- Misses        103      258      +155     
- Partials        0        2        +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zoe-codez zoe-codez merged commit 36516d8 into main Sep 25, 2024
1 check passed
@zoe-codez zoe-codez deleted the serialize branch September 25, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant