@pburtchaell/homebridge-seasons 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +1 -0
- package/AGENTS.md +5 -0
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/config.schema.json +45 -0
- package/index.js +205 -0
- package/package.json +40 -0
- package/test/homebridge/accessories/cachedAccessories +1 -0
- package/test/homebridge/config.json +17 -0
- package/test/homebridge/persist/AccessoryInfo.AABBCCDDEEFF.json +1 -0
- package/test/homebridge/persist/IdentifierCache.AABBCCDDEEFF.json +1 -0
- package/test/index.test.js +250 -0
- package/vitest.config.js +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm run lint && npm test
|
package/AGENTS.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Burtchaell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# homebridge-seasons
|
|
2
|
+
[](https://www.npmjs.com/package/@pburtchaell/homebridge-seasons)
|
|
3
|
+
[](https://www.npmjs.com/package/@pburtchaell/homebridge-seasons)
|
|
4
|
+
[](https://github.com/pburtchaell/homebridge-seasons)
|
|
5
|
+
|
|
6
|
+
This is a plugin for [homebridge](https://github.com/homebridge/homebridge) that displays the current season of the year. You can download it via [npm](https://www.npmjs.com/package/@pburtchaell/homebridge-seasons).
|
|
7
|
+
|
|
8
|
+
This project is a fork of the [original plugin](https://github.com/naofireblade/homebridge-seasons) by [Arne Blumentritt](https://github.com/naofireblade). Thanks to Arne for creating and maintaining this plugin.
|
|
9
|
+
|
|
10
|
+
Feel free to leave any feedback [here](https://github.com/pburtchaell/homebridge-seasons/issues).
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Meteorologic season
|
|
15
|
+
- Astronomic season
|
|
16
|
+
- Nothern and southern hemisphere
|
|
17
|
+
- Number and name representation of the season
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
1. Install homebridge using: `npm install -g homebridge`
|
|
22
|
+
2. Install this plugin using: `npm install -g @pburtchaell/homebridge-seasons`
|
|
23
|
+
3. Update your configuration file. See the samples below.
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
Add the following information to your config file.
|
|
28
|
+
|
|
29
|
+
- You can choose between the *meteorologic* and *astronomic* **calendar**.
|
|
30
|
+
- You can set your **hemisphere** between *north* and *south*.
|
|
31
|
+
- And you can decide whether you want to **display** the season as a *number* (0 = Spring), a *name* or *both*. The number representation can be used in homekit rules.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
"platforms": [
|
|
36
|
+
{
|
|
37
|
+
"platform": "Seasons",
|
|
38
|
+
"name": "Seasons",
|
|
39
|
+
"calendar": "meteorologic",
|
|
40
|
+
"hemisphere": "north",
|
|
41
|
+
"display": "both"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "Seasons",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"title": "Name",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"default": "Seasons",
|
|
12
|
+
"required": true
|
|
13
|
+
},
|
|
14
|
+
"calendar": {
|
|
15
|
+
"title": "Calendar",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"default": "meteorologic",
|
|
18
|
+
"description": "Astronomic uses the solstices and equinoxes for precise seasonal dates, while meteorologic uses fixed months like Dec-Feb for Winter, Mar-May for Spring, etc.",
|
|
19
|
+
"oneOf": [
|
|
20
|
+
{ "title": "Meteorologic", "enum": ["meteorologic"] },
|
|
21
|
+
{ "title": "Astronomic", "enum": ["astronomic"] }
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"hemisphere": {
|
|
25
|
+
"title": "Hemisphere",
|
|
26
|
+
"type": "string",
|
|
27
|
+
"default": "north",
|
|
28
|
+
"oneOf": [
|
|
29
|
+
{ "title": "Northern", "enum": ["north"] },
|
|
30
|
+
{ "title": "Southern", "enum": ["south"] }
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"display": {
|
|
34
|
+
"title": "Display",
|
|
35
|
+
"type": "string",
|
|
36
|
+
"default": "both",
|
|
37
|
+
"oneOf": [
|
|
38
|
+
{ "title": "Both (number and name)", "enum": ["both"] },
|
|
39
|
+
{ "title": "Number only", "enum": ["number"] },
|
|
40
|
+
{ "title": "Name only", "enum": ["name"] }
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const CustomUUID = {
|
|
4
|
+
SeasonService: "ca741310-c62e-454b-a63b-3a1db3ca2c3a",
|
|
5
|
+
SeasonCharacteristic: "9382ccde-6cab-42e7-877a-2df98b8d0b66",
|
|
6
|
+
SeasonNameCharacteristic: "02e4c0e3-44f9-44b8-8667-98f54b376ce4",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const Seasons = {
|
|
10
|
+
Spring: "Spring",
|
|
11
|
+
Summer: "Summer",
|
|
12
|
+
Autumn: "Autumn",
|
|
13
|
+
Winter: "Winter",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const SeasonNumber = {
|
|
17
|
+
[Seasons.Spring]: 0,
|
|
18
|
+
[Seasons.Summer]: 1,
|
|
19
|
+
[Seasons.Autumn]: 2,
|
|
20
|
+
[Seasons.Winter]: 3,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let Service;
|
|
24
|
+
let Characteristic;
|
|
25
|
+
let Formats;
|
|
26
|
+
let Perms;
|
|
27
|
+
let SeasonService;
|
|
28
|
+
let SeasonCharacteristic;
|
|
29
|
+
let SeasonNameCharacteristic;
|
|
30
|
+
|
|
31
|
+
module.exports = function (homebridge) {
|
|
32
|
+
Service = homebridge.hap.Service;
|
|
33
|
+
Characteristic = homebridge.hap.Characteristic;
|
|
34
|
+
Formats = homebridge.hap.Formats;
|
|
35
|
+
Perms = homebridge.hap.Perms;
|
|
36
|
+
|
|
37
|
+
// Custom Season Service
|
|
38
|
+
SeasonService = class extends Service {
|
|
39
|
+
constructor(displayName, subtype) {
|
|
40
|
+
super(displayName, CustomUUID.SeasonService, subtype);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Custom Season Characteristic (numeric value 0-3)
|
|
45
|
+
SeasonCharacteristic = class extends Characteristic {
|
|
46
|
+
constructor() {
|
|
47
|
+
super("Season", CustomUUID.SeasonCharacteristic);
|
|
48
|
+
this.setProps({
|
|
49
|
+
format: Formats.UINT8,
|
|
50
|
+
maxValue: 3,
|
|
51
|
+
minValue: 0,
|
|
52
|
+
minStep: 1,
|
|
53
|
+
perms: [Perms.READ, Perms.NOTIFY],
|
|
54
|
+
});
|
|
55
|
+
this.value = this.getDefaultValue();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Custom Season Name Characteristic (string value)
|
|
60
|
+
SeasonNameCharacteristic = class extends Characteristic {
|
|
61
|
+
constructor() {
|
|
62
|
+
super("Season Name", CustomUUID.SeasonNameCharacteristic);
|
|
63
|
+
this.setProps({
|
|
64
|
+
format: Formats.STRING,
|
|
65
|
+
perms: [Perms.READ, Perms.NOTIFY],
|
|
66
|
+
});
|
|
67
|
+
this.value = this.getDefaultValue();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
homebridge.registerPlatform("@pburtchaell/homebridge-seasons", "Seasons", SeasonsPlatform);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
class SeasonsPlatform {
|
|
75
|
+
constructor(log, config) {
|
|
76
|
+
this.log = log;
|
|
77
|
+
this.config = config;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
accessories(callback) {
|
|
81
|
+
const accessories = [];
|
|
82
|
+
accessories.push(new SeasonsAccessory(this));
|
|
83
|
+
callback(accessories);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class SeasonsAccessory {
|
|
88
|
+
constructor(platform) {
|
|
89
|
+
this.log = platform.log;
|
|
90
|
+
this.config = platform.config;
|
|
91
|
+
this.name = "Season";
|
|
92
|
+
|
|
93
|
+
// Get calendar type from config (default: meteorologic)
|
|
94
|
+
this.calendar = this.config.calendar || "meteorologic";
|
|
95
|
+
|
|
96
|
+
// Get hemisphere from config (default: north)
|
|
97
|
+
this.hemisphere = this.config.hemisphere || "north";
|
|
98
|
+
|
|
99
|
+
// Get display mode from config (default: both)
|
|
100
|
+
this.display = this.config.display || "both";
|
|
101
|
+
|
|
102
|
+
// Setup accessory information service
|
|
103
|
+
this.informationService = new Service.AccessoryInformation();
|
|
104
|
+
this.informationService
|
|
105
|
+
.setCharacteristic(Characteristic.Manufacturer, "Homebridge Seasons")
|
|
106
|
+
.setCharacteristic(Characteristic.Model, "Seasons Sensor")
|
|
107
|
+
.setCharacteristic(Characteristic.SerialNumber, "HB-SEASONS-001")
|
|
108
|
+
.setCharacteristic(Characteristic.FirmwareRevision, "1.0.0");
|
|
109
|
+
|
|
110
|
+
// Create season service and add characteristics depending on config
|
|
111
|
+
this.seasonService = new SeasonService(this.name);
|
|
112
|
+
|
|
113
|
+
if (this.display === "both" || this.display === "number") {
|
|
114
|
+
this.seasonService.addCharacteristic(SeasonCharacteristic);
|
|
115
|
+
this.seasonService
|
|
116
|
+
.getCharacteristic(SeasonCharacteristic)
|
|
117
|
+
.on("get", this.getCurrentSeason.bind(this));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (this.display === "both" || this.display === "name") {
|
|
121
|
+
this.seasonService.addCharacteristic(SeasonNameCharacteristic);
|
|
122
|
+
this.seasonService
|
|
123
|
+
.getCharacteristic(SeasonNameCharacteristic)
|
|
124
|
+
.on("get", this.getCurrentSeasonName.bind(this));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
identify(callback) {
|
|
129
|
+
this.log.debug("Identify requested");
|
|
130
|
+
callback();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getServices() {
|
|
134
|
+
return [this.informationService, this.seasonService];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getCurrentSeason(callback) {
|
|
138
|
+
this.getCurrentSeasonName((error, name) => {
|
|
139
|
+
callback(null, SeasonNumber[name]);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getCurrentSeasonName(callback) {
|
|
144
|
+
let season;
|
|
145
|
+
|
|
146
|
+
if (this.calendar === "meteorologic") {
|
|
147
|
+
this.log.debug("Using meteorologic calendar to get current season");
|
|
148
|
+
season = this.getMeteorologicSeason(new Date());
|
|
149
|
+
} else {
|
|
150
|
+
this.log.debug("Using astronomic calendar to get current season");
|
|
151
|
+
const northernHemisphere = this.hemisphere === "north";
|
|
152
|
+
this.log.debug("Hemisphere is " + (northernHemisphere ? "north" : "south"));
|
|
153
|
+
season = this.getAstronomicSeason(new Date(), northernHemisphere);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.log.debug("Current season is " + season);
|
|
157
|
+
callback(null, season);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getMeteorologicSeason(date) {
|
|
161
|
+
const month = date.getMonth() + 1;
|
|
162
|
+
|
|
163
|
+
if (month >= 3 && month <= 5) { return Seasons.Spring; }
|
|
164
|
+
if (month >= 6 && month <= 8) { return Seasons.Summer; }
|
|
165
|
+
if (month >= 9 && month <= 11) { return Seasons.Autumn; }
|
|
166
|
+
return Seasons.Winter;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Calculate astronomical season based on solstices and equinoxes.
|
|
171
|
+
* Approximate dates (varies by ~1 day year to year):
|
|
172
|
+
* - Spring Equinox: March 20
|
|
173
|
+
* - Summer Solstice: June 21
|
|
174
|
+
* - Autumn Equinox: September 22
|
|
175
|
+
* - Winter Solstice: December 21
|
|
176
|
+
*/
|
|
177
|
+
getAstronomicSeason(date, northernHemisphere) {
|
|
178
|
+
const month = date.getMonth() + 1;
|
|
179
|
+
const day = date.getDate();
|
|
180
|
+
|
|
181
|
+
let season;
|
|
182
|
+
|
|
183
|
+
if ((month === 3 && day >= 20) || month === 4 || month === 5 || (month === 6 && day < 21)) {
|
|
184
|
+
season = Seasons.Spring;
|
|
185
|
+
} else if ((month === 6 && day >= 21) || month === 7 || month === 8 || (month === 9 && day < 22)) {
|
|
186
|
+
season = Seasons.Summer;
|
|
187
|
+
} else if ((month === 9 && day >= 22) || month === 10 || month === 11 || (month === 12 && day < 21)) {
|
|
188
|
+
season = Seasons.Autumn;
|
|
189
|
+
} else {
|
|
190
|
+
season = Seasons.Winter;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!northernHemisphere) {
|
|
194
|
+
const opposite = {
|
|
195
|
+
[Seasons.Spring]: Seasons.Autumn,
|
|
196
|
+
[Seasons.Summer]: Seasons.Winter,
|
|
197
|
+
[Seasons.Autumn]: Seasons.Spring,
|
|
198
|
+
[Seasons.Winter]: Seasons.Summer,
|
|
199
|
+
};
|
|
200
|
+
season = opposite[season];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return season;
|
|
204
|
+
}
|
|
205
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": false,
|
|
3
|
+
"name": "@pburtchaell/homebridge-seasons",
|
|
4
|
+
"displayName": "Seasons",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"description": "A plugin to display the current season of the year",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"homebridge-plugin",
|
|
11
|
+
"season",
|
|
12
|
+
"seasons"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.0.0",
|
|
16
|
+
"homebridge": "^1.6.0 || ^2.0.0-beta.0"
|
|
17
|
+
},
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Patrick Burtchaell <patrick@pburtchaell.com> (pburtchaell.com)"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"lint": "eslint . --max-warnings=0",
|
|
24
|
+
"prepublishOnly": "npm run lint && npm test",
|
|
25
|
+
"prepare": "husky",
|
|
26
|
+
"dev": "npm link && nodemon"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git://github.com/pburtchaell/homebridge-seasons.git"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@eslint/js": "^10.0.1",
|
|
34
|
+
"eslint": "^10.0.0",
|
|
35
|
+
"homebridge": "^2.0.0-beta.0",
|
|
36
|
+
"husky": "^9.1.7",
|
|
37
|
+
"nodemon": "^3.0.0",
|
|
38
|
+
"vitest": "^3.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bridge": {
|
|
3
|
+
"name": "SeasonsDevBridge",
|
|
4
|
+
"username": "AA:BB:CC:DD:EE:FF",
|
|
5
|
+
"port": 51826,
|
|
6
|
+
"pin": "031-45-154"
|
|
7
|
+
},
|
|
8
|
+
"platforms": [
|
|
9
|
+
{
|
|
10
|
+
"name": "Seasons",
|
|
11
|
+
"platform": "Seasons",
|
|
12
|
+
"calendar": "meteorologic",
|
|
13
|
+
"hemisphere": "north",
|
|
14
|
+
"display": "both"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"displayName":"SeasonsDevBridge 702C","category":2,"pincode":"031-45-154","signSk":"76a5e4a5c24fd5003d9ad0faf10caffb82e399c68e6f8d6c613903da57b797af9a6304ad55a8a83f0da6e37abb61dd459416517000f62e820574d75599926828","signPk":"9a6304ad55a8a83f0da6e37abb61dd459416517000f62e820574d75599926828","pairedClients":{},"pairedClientsPermission":{},"configVersion":2,"configHash":"8c7eda26fad8d979384af44d65715bf904f5558d","setupID":"OXVI","lastFirmwareVersion":"0.11.2"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"cache":{"f6f986a8-ae40-4f38-aa34-4b232ed91fca|nextIID":10,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|0000003E-0000-1000-8000-0026BB765291|00000014-0000-1000-8000-0026BB765291":2,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|0000003E-0000-1000-8000-0026BB765291|00000020-0000-1000-8000-0026BB765291":3,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|0000003E-0000-1000-8000-0026BB765291|00000021-0000-1000-8000-0026BB765291":4,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|0000003E-0000-1000-8000-0026BB765291|00000023-0000-1000-8000-0026BB765291":5,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|0000003E-0000-1000-8000-0026BB765291|00000030-0000-1000-8000-0026BB765291":6,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|0000003E-0000-1000-8000-0026BB765291|00000052-0000-1000-8000-0026BB765291":7,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|000000A2-0000-1000-8000-0026BB765291":8,"f6f986a8-ae40-4f38-aa34-4b232ed91fca|000000A2-0000-1000-8000-0026BB765291|00000037-0000-1000-8000-0026BB765291":9,"|nextAID":3,"25ec2c37-426c-4b8e-a20f-976770fa1af5":2,"25ec2c37-426c-4b8e-a20f-976770fa1af5|nextIID":12,"25ec2c37-426c-4b8e-a20f-976770fa1af5|0000003E-0000-1000-8000-0026BB765291|00000014-0000-1000-8000-0026BB765291":2,"25ec2c37-426c-4b8e-a20f-976770fa1af5|0000003E-0000-1000-8000-0026BB765291|00000020-0000-1000-8000-0026BB765291":3,"25ec2c37-426c-4b8e-a20f-976770fa1af5|0000003E-0000-1000-8000-0026BB765291|00000021-0000-1000-8000-0026BB765291":4,"25ec2c37-426c-4b8e-a20f-976770fa1af5|0000003E-0000-1000-8000-0026BB765291|00000023-0000-1000-8000-0026BB765291":5,"25ec2c37-426c-4b8e-a20f-976770fa1af5|0000003E-0000-1000-8000-0026BB765291|00000030-0000-1000-8000-0026BB765291":6,"25ec2c37-426c-4b8e-a20f-976770fa1af5|0000003E-0000-1000-8000-0026BB765291|00000052-0000-1000-8000-0026BB765291":7,"25ec2c37-426c-4b8e-a20f-976770fa1af5|ca741310-c62e-454b-a63b-3a1db3ca2c3a":8,"25ec2c37-426c-4b8e-a20f-976770fa1af5|ca741310-c62e-454b-a63b-3a1db3ca2c3a|00000023-0000-1000-8000-0026BB765291":9,"25ec2c37-426c-4b8e-a20f-976770fa1af5|ca741310-c62e-454b-a63b-3a1db3ca2c3a|9382ccde-6cab-42e7-877a-2df98b8d0b66":10,"25ec2c37-426c-4b8e-a20f-976770fa1af5|ca741310-c62e-454b-a63b-3a1db3ca2c3a|02e4c0e3-44f9-44b8-8667-98f54b376ce4":11}}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// --- Mock Homebridge HAP API ---
|
|
2
|
+
|
|
3
|
+
function createHomebridgeMock() {
|
|
4
|
+
class MockCharacteristic {
|
|
5
|
+
constructor(name, uuid) {
|
|
6
|
+
this.displayName = name;
|
|
7
|
+
this.UUID = uuid;
|
|
8
|
+
this.value = null;
|
|
9
|
+
this._props = {};
|
|
10
|
+
this._handlers = {};
|
|
11
|
+
}
|
|
12
|
+
setProps(props) {
|
|
13
|
+
this._props = props;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
getDefaultValue() {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
on(event, handler) {
|
|
20
|
+
this._handlers[event] = handler;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
MockCharacteristic.Formats = { UINT8: "uint8", STRING: "string" };
|
|
26
|
+
MockCharacteristic.Perms = { READ: "pr", NOTIFY: "ev" };
|
|
27
|
+
MockCharacteristic.Manufacturer = "manufacturer";
|
|
28
|
+
MockCharacteristic.Model = "model";
|
|
29
|
+
MockCharacteristic.SerialNumber = "serialnumber";
|
|
30
|
+
MockCharacteristic.FirmwareRevision = "firmwarerevision";
|
|
31
|
+
|
|
32
|
+
class MockService {
|
|
33
|
+
constructor(displayName, uuid, subtype) {
|
|
34
|
+
this.displayName = displayName;
|
|
35
|
+
this.UUID = uuid;
|
|
36
|
+
this.subtype = subtype;
|
|
37
|
+
this._characteristics = new Map();
|
|
38
|
+
}
|
|
39
|
+
addCharacteristic(CharClass) {
|
|
40
|
+
const inst = new CharClass();
|
|
41
|
+
this._characteristics.set(CharClass, inst);
|
|
42
|
+
return inst;
|
|
43
|
+
}
|
|
44
|
+
getCharacteristic(key) {
|
|
45
|
+
if (this._characteristics.has(key)) {
|
|
46
|
+
return this._characteristics.get(key);
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
setCharacteristic() {
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
MockService.AccessoryInformation = class extends MockService {
|
|
56
|
+
constructor() {
|
|
57
|
+
super("Accessory Information", "0000003E-0000-1000-8000-0026BB765291");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let PlatformClass = null;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
hap: {
|
|
65
|
+
Service: MockService,
|
|
66
|
+
Characteristic: MockCharacteristic,
|
|
67
|
+
Formats: { UINT8: "uint8", STRING: "string" },
|
|
68
|
+
Perms: { READ: "pr", NOTIFY: "ev" },
|
|
69
|
+
},
|
|
70
|
+
registerPlatform(id, name, cls) {
|
|
71
|
+
PlatformClass = cls;
|
|
72
|
+
},
|
|
73
|
+
get PlatformClass() {
|
|
74
|
+
return PlatformClass;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// --- Setup ---
|
|
80
|
+
|
|
81
|
+
const mock = createHomebridgeMock();
|
|
82
|
+
require("../index")(mock);
|
|
83
|
+
|
|
84
|
+
function createAccessory(config = {}) {
|
|
85
|
+
const defaults = {
|
|
86
|
+
name: "Seasons",
|
|
87
|
+
platform: "Seasons",
|
|
88
|
+
calendar: "meteorologic",
|
|
89
|
+
hemisphere: "north",
|
|
90
|
+
display: "both",
|
|
91
|
+
};
|
|
92
|
+
const log = Object.assign(() => {}, { debug() {} });
|
|
93
|
+
const platform = new mock.PlatformClass(log, { ...defaults, ...config });
|
|
94
|
+
let accessory;
|
|
95
|
+
platform.accessories((accs) => {
|
|
96
|
+
accessory = accs[0];
|
|
97
|
+
});
|
|
98
|
+
return accessory;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function date(month, day) {
|
|
102
|
+
return new Date(2025, month - 1, day);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// --- Tests ---
|
|
106
|
+
|
|
107
|
+
describe("Meteorologic seasons", () => {
|
|
108
|
+
const accessory = createAccessory({ calendar: "meteorologic" });
|
|
109
|
+
|
|
110
|
+
const cases = [
|
|
111
|
+
[1, "Winter"],
|
|
112
|
+
[2, "Winter"],
|
|
113
|
+
[3, "Spring"],
|
|
114
|
+
[4, "Spring"],
|
|
115
|
+
[5, "Spring"],
|
|
116
|
+
[6, "Summer"],
|
|
117
|
+
[7, "Summer"],
|
|
118
|
+
[8, "Summer"],
|
|
119
|
+
[9, "Autumn"],
|
|
120
|
+
[10, "Autumn"],
|
|
121
|
+
[11, "Autumn"],
|
|
122
|
+
[12, "Winter"],
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
for (const [month, expected] of cases) {
|
|
126
|
+
it(`month ${month} → ${expected}`, () => {
|
|
127
|
+
expect(accessory.getMeteorologicSeason(date(month, 15))).toBe(expected);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("Astronomic seasons (northern hemisphere)", () => {
|
|
133
|
+
const accessory = createAccessory({
|
|
134
|
+
calendar: "astronomic",
|
|
135
|
+
hemisphere: "north",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const cases = [
|
|
139
|
+
// Spring equinox boundary (Mar 20)
|
|
140
|
+
[3, 19, "Winter"],
|
|
141
|
+
[3, 20, "Spring"],
|
|
142
|
+
[3, 21, "Spring"],
|
|
143
|
+
// Summer solstice boundary (Jun 21)
|
|
144
|
+
[6, 20, "Spring"],
|
|
145
|
+
[6, 21, "Summer"],
|
|
146
|
+
[6, 22, "Summer"],
|
|
147
|
+
// Autumn equinox boundary (Sep 22)
|
|
148
|
+
[9, 21, "Summer"],
|
|
149
|
+
[9, 22, "Autumn"],
|
|
150
|
+
[9, 23, "Autumn"],
|
|
151
|
+
// Winter solstice boundary (Dec 21)
|
|
152
|
+
[12, 20, "Autumn"],
|
|
153
|
+
[12, 21, "Winter"],
|
|
154
|
+
[12, 22, "Winter"],
|
|
155
|
+
// Mid-season checks
|
|
156
|
+
[1, 15, "Winter"],
|
|
157
|
+
[4, 15, "Spring"],
|
|
158
|
+
[7, 15, "Summer"],
|
|
159
|
+
[10, 15, "Autumn"],
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
for (const [month, day, expected] of cases) {
|
|
163
|
+
it(`${month}/${day} → ${expected}`, () => {
|
|
164
|
+
expect(accessory.getAstronomicSeason(date(month, day), true)).toBe(
|
|
165
|
+
expected,
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("Astronomic seasons (southern hemisphere)", () => {
|
|
172
|
+
const accessory = createAccessory({
|
|
173
|
+
calendar: "astronomic",
|
|
174
|
+
hemisphere: "south",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const cases = [
|
|
178
|
+
// Hemisphere inversion: north season → opposite in south
|
|
179
|
+
[1, 15, "Summer"],
|
|
180
|
+
[4, 15, "Autumn"],
|
|
181
|
+
[7, 15, "Winter"],
|
|
182
|
+
[10, 15, "Spring"],
|
|
183
|
+
// Boundaries also flip
|
|
184
|
+
[3, 19, "Summer"],
|
|
185
|
+
[3, 20, "Autumn"],
|
|
186
|
+
[6, 21, "Winter"],
|
|
187
|
+
[9, 22, "Spring"],
|
|
188
|
+
[12, 21, "Summer"],
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
for (const [month, day, expected] of cases) {
|
|
192
|
+
it(`${month}/${day} → ${expected}`, () => {
|
|
193
|
+
expect(accessory.getAstronomicSeason(date(month, day), false)).toBe(
|
|
194
|
+
expected,
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("Config integration", () => {
|
|
201
|
+
it("applies default config values", () => {
|
|
202
|
+
const accessory = createAccessory({});
|
|
203
|
+
expect(accessory.calendar).toBe("meteorologic");
|
|
204
|
+
expect(accessory.hemisphere).toBe("north");
|
|
205
|
+
expect(accessory.display).toBe("both");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("getCurrentSeason returns number matching season name", () => {
|
|
209
|
+
return new Promise((resolve) => {
|
|
210
|
+
const accessory = createAccessory({ calendar: "meteorologic" });
|
|
211
|
+
accessory.getCurrentSeasonName((err, name) => {
|
|
212
|
+
accessory.getCurrentSeason((err2, number) => {
|
|
213
|
+
const seasonNumbers = { Spring: 0, Summer: 1, Autumn: 2, Winter: 3 };
|
|
214
|
+
expect(number).toBe(seasonNumbers[name]);
|
|
215
|
+
resolve();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("Display mode wiring", () => {
|
|
223
|
+
it("'both' registers number and name characteristics", () => {
|
|
224
|
+
const accessory = createAccessory({ display: "both" });
|
|
225
|
+
expect(accessory.seasonService._characteristics.size).toBe(2);
|
|
226
|
+
|
|
227
|
+
// Both should have get handlers
|
|
228
|
+
for (const [, char] of accessory.seasonService._characteristics) {
|
|
229
|
+
expect(typeof char._handlers.get).toBe("function");
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("'number' registers only the numeric characteristic", () => {
|
|
234
|
+
const accessory = createAccessory({ display: "number" });
|
|
235
|
+
expect(accessory.seasonService._characteristics.size).toBe(1);
|
|
236
|
+
|
|
237
|
+
const [, char] = [...accessory.seasonService._characteristics][0];
|
|
238
|
+
expect(char.UUID).toBe("9382ccde-6cab-42e7-877a-2df98b8d0b66");
|
|
239
|
+
expect(typeof char._handlers.get).toBe("function");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("'name' registers only the name characteristic", () => {
|
|
243
|
+
const accessory = createAccessory({ display: "name" });
|
|
244
|
+
expect(accessory.seasonService._characteristics.size).toBe(1);
|
|
245
|
+
|
|
246
|
+
const [, char] = [...accessory.seasonService._characteristics][0];
|
|
247
|
+
expect(char.UUID).toBe("02e4c0e3-44f9-44b8-8667-98f54b376ce4");
|
|
248
|
+
expect(typeof char._handlers.get).toBe("function");
|
|
249
|
+
});
|
|
250
|
+
});
|