Skip to content

feat: schedule/calendar write#65

Closed
EveGun wants to merge 15 commits intobacnet-js:masterfrom
EveGun:feature/schedule-calendar-write
Closed

feat: schedule/calendar write#65
EveGun wants to merge 15 commits intobacnet-js:masterfrom
EveGun:feature/schedule-calendar-write

Conversation

@EveGun
Copy link
Contributor

@EveGun EveGun commented Feb 11, 2026

Summary

This PR ports schedule/calendar write compatibility from the legacy node-bacstack implementation into @bacnet-js/client, and adds write examples for manual validation.

Source reference:

What changed

  • Added specialized encode paths in WriteProperty.encode for:
  • WEEKLY_SCHEDULE
  • EXCEPTION_SCHEDULE
  • EFFECTIVE_PERIOD
  • DATE_LIST
  • Added dedicated payload encoders in src/lib/services/WriteProperty.ts for weekly schedule, exception schedule, effective period, and calendar date list.
  • Added stricter validation before encoding:
  • weekly schedule must have exactly 7 day arrays
  • exception schedule priority must be in range 1..16
  • DATERANGE entries must contain exactly 2 dates
  • WEEKNDAY values are validated (including wildcard 0xff)
  • raw date byte input (year/month/day/wday) is validated
  • Added write examples:
  • examples/write-schedule-weekly.ts
  • examples/write-schedule-exception.ts
  • examples/write-schedule-period.ts
  • examples/write-calendar-datelist.ts
  • Updated example CLI behavior so target accepts host[:port], with optional local bind port as separate argument.
  • Added/extended unit tests in test/unit/service-write-property.spec.ts for schedule/calendar write compatibility and failure cases.

Type consistency

  • Kept the existing public writeProperty contract unchanged.
  • Invalid payloads now fail fast with explicit validation errors instead of encoding malformed APDUs.

Validation

  • npm run lint ✅
  • npm run test:unit ✅
  • Docker-based compliance tests executed successfully in local environment ✅
  • Manually validated against a WAGO PFC200 device ✅

Notes

  • Manually validated write behavior against WAGO PFC200 schedule/calendar objects. Full roundtrip tested.
  • Emulator-related legacy hacks are intentionally not included in this PR.
  • Schedule/calendar compatibility payloads are currently supported in writeProperty only. writePropertyMultiple is unchanged and does not yet support these specialized payload shapes.

@coveralls
Copy link

coveralls commented Feb 11, 2026

Pull Request Test Coverage Report for Build 21911669099

Details

  • 116 of 142 (81.69%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.6%) to 83.597%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/lib/services/WriteProperty.ts 116 142 81.69%
Files with Coverage Reduction New Missed Lines %
src/lib/services/WriteProperty.ts 1 80.84%
Totals Coverage Status
Change from base Build 21907071234: 0.6%
Covered Lines: 5326
Relevant Lines: 6063

💛 - Coveralls

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds BACnet Schedule/Calendar write compatibility to @bacnet-js/client by introducing dedicated WriteProperty.encode paths for schedule/calendar properties, along with new write examples and unit tests to validate encoding and fast-fail validation.

Changes:

  • Added specialized encoding + validation for WEEKLY_SCHEDULE, EXCEPTION_SCHEDULE, EFFECTIVE_PERIOD, and DATE_LIST in WriteProperty.encode.
  • Added/extended unit tests covering schedule/calendar write encoding and rejection cases.
  • Added new example scripts to manually write schedule/calendar payloads to devices.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/lib/services/WriteProperty.ts Adds custom encoders/validators for schedule/calendar write payloads and routes encoding based on object/property ids.
test/unit/service-write-property.spec.ts Adds unit tests for the new schedule/calendar write encode paths and validation failures.
examples/write-schedule-weekly.ts Adds a manual weekly schedule write example.
examples/write-schedule-exception.ts Adds a manual exception schedule write example.
examples/write-schedule-period.ts Adds a manual effective period write example.
examples/write-calendar-datelist.ts Adds a manual calendar date list write example.

@EveGun
Copy link
Contributor Author

EveGun commented Feb 11, 2026

Will look into Copilot responses.

@EveGun EveGun closed this Feb 16, 2026
@robertsLando
Copy link
Member

Hi @EveGun Why did you closed the PR?

@EveGun
Copy link
Contributor Author

EveGun commented Feb 16, 2026

Hi @EveGun Why did you closed the PR?

I might found a minor issue in the encoding of exception dates with wildcards. When porting my old code, i changed some variable datatypes from epoch timestamps to date objects and think this might introduced a small bug.

Im investigating this now and will reopen when solved.

Im new to contributing to open source projects. Sorry if this is a bad approach. 😬

@robertsLando
Copy link
Member

@EveGun no worries was just to know, will wait for the new PR then :)

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.

4 participants