Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
* Added different calendars (astronomic and meteorologic)
* Added different hemisphere (north and south)
* Added different display types (number, name, both)
  • Loading branch information
naofireblade committed Jan 28, 2018
1 parent 51be04c commit 340c43e
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 17 deletions.
17 changes: 0 additions & 17 deletions .gitattributes

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.0.0

* Added different calendars (astronomic and meteorologic)
* Added different hemisphere (north and south)
* Added different display types (number, name, both)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Arne Blumentritt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# homebridge-seaons

This is a plugin for [homebridge](https://github.com/nfarina/homebridge) that displays the current season of the year. You can download it via [npm](https://www.npmjs.com/package/homebridge-seasons).

Feel free to leave any feedback [here](https://github.com/naofireblade/homebridge-seasons/issues).

## Features

- Meteorologic season
- Astronomic season
- Nothern and southern hemisphere
- Number and name representation of season

## Installation

1. Install homebridge using: `npm install -g homebridge`
2. Install this plugin using: `npm install -g homebridge-seasons`
3. Update your configuration file. See the samples below.

## Configuration

Add the following information to your config file.

You can choose between the *meteorologic* and *astronomic* calendar.
You can set your hemisphere between *north* and *south*.
And you can decide whether you want to see the season as a *number* (0 = Spring), a *name* or *both*. The number representation can be used in homekit rules.


```json
"platforms": [
{
"platform": "Seasons",
"name": "Seasons",
"calendar": "meteorologic",
"hemisphere": "north",
"display": "both"
}
]
```
173 changes: 173 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
"use strict";

var inherits = require("util").inherits;
var debug = require("debug")("homebridge-seasons"),
seasonCalculator = require("date-season");

var Service,
Characteristic,

CustomUUID = {
SeasonService: "ca741310-c62e-454b-a63b-3a1db3ca2c3a",
SeasonCharacteristic: "9382ccde-6cab-42e7-877a-2df98b8d0b66",
SeasonNameCharacteristic: "02e4c0e3-44f9-44b8-8667-98f54b376ce4",
},
SeasonService,
SeasonCharacteristic,
SeasonNameCharacteristic;

module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerPlatform("homebridge-seasons", "Seasons", SeasonsPlatform);

SeasonService = function(displayName, subtype) {
Service.call(this, displayName, CustomUUID.SeasonService, subtype);
};
inherits(SeasonService, Service);

SeasonCharacteristic = function() {
Characteristic.call(this, "Season", CustomUUID.SeasonCharacteristic);
this.setProps({
format: Characteristic.Formats.UINT8,
maxValue: 3,
minValue: 0,
minStep: 1,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
inherits(SeasonCharacteristic, Characteristic);

SeasonNameCharacteristic = function() {
Characteristic.call(this, "Season Name", CustomUUID.SeasonNameCharacteristic);
this.setProps({
format: Characteristic.Formats.STRING,
perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
});
this.value = this.getDefaultValue();
};
inherits(SeasonNameCharacteristic, Characteristic);
}

function SeasonsPlatform(log, config) {
this.log = log;
this.config = config;
}

SeasonsPlatform.prototype = {
accessories: function(callback) {

this.accessories = [];
this.accessories.push(new SeasonsAccessory(this));

callback(this.accessories);
}
}

function SeasonsAccessory(platform) {
this.log = platform.log;
this.config = platform.config;
this.name = "Season";

this.informationService = new Service.AccessoryInformation();
this.informationService.setCharacteristic(Characteristic.Manufacturer, "Homebridge Seasons");
this.informationService.setCharacteristic(Characteristic.Model, "github.com/naofireblade/homebridge-seasons");

// Get calendar type from config
this.calendar = ("calendar" in this.config ? this.config["calendar"] : "meteorologic");

// Get hemisphere from config
this.hemisphere = ("hemisphere" in this.config ? this.config["hemisphere"] : "north");

// Create service and add characteristics depending on config
this.seasonService = new SeasonService(this.name);
if (this.config["display"] === "both" || this.config["display"] === "number") {
this.seasonService.addCharacteristic(SeasonCharacteristic);
this.seasonService.getCharacteristic(SeasonCharacteristic).on("get", this.getCurrentSeason.bind(this));
}
if (this.config["display"] === "both" || this.config["display"] === "name") {
this.seasonService.addCharacteristic(SeasonNameCharacteristic);
this.seasonService.getCharacteristic(SeasonNameCharacteristic).on("get", this.getCurrentSeasonName.bind(this));
}
}

SeasonsAccessory.prototype = {
identify: function (callback) {
debug("Identify requested");
callback();
},

getServices: function () {
return [this.informationService, this.seasonService];
},

getCurrentSeason: function(callback) {
let that = this;
this.getCurrentSeasonName(function (error, result) {
let season;
if (result === "Spring") {
season = 0;
}
else if (result === "Summer") {
season = 1;
}
else if (result === "Autumn") {
season = 2;
}
else if (result === "Winter") {
season = 3;
}
else {
that.log.error("Unkown season " + result);
}
callback(false, season);
});
},

getCurrentSeasonName: function(callback) {
let seasonName;
if (this.calendar === "meteorologic") {
debug("Using meteorologic calendar to get current season");
let month = (new Date()).getMonth() + 1;
switch (month) {
case 1:
case 2:
case 12:
seasonName = "Winter";
break;
case 3:
case 4:
case 5:
seasonName = "Spring";
break;
case 6:
case 7:
case 8:
seasonName = "Autumn";
break;
case 9:
case 10:
case 11:
seasonName = "Winter";
break;
}
}
else {
debug("Using astronomic calendar to get current season");

let northernHemisphere = this.hemisphere === "north";
if (northernHemisphere) {
debug("Hemisphere is north");
}
else {
debug("Hemisphere is south");
}

let astronomicCalendar = seasonCalculator({ north: northernHemisphere, autumn: true });
seasonName = astronomicCalendar(new Date())
}
debug("Current season is " + seasonName);
callback(false, seasonName);
}
}
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "homebridge-seasons",
"version": "1.0.0",
"description": "A plugin to display the current season of the year.",
"license": "MIT",
"keywords": [
"homebridge-plugin",
"season",
"seasons"
],
"engines": {
"node": ">=0.12.0",
"homebridge": ">=0.2.0"
},
"author": {
"name": "Arne Blumentritt"
},
"repository": {
"type": "git",
"url": "git://github.com/naofireblade/homebridge-seasons.git"
},
"dependencies": {
"debug": "^2.2.0",
"date-season": "^0.0.2"
}
}

0 comments on commit 340c43e

Please sign in to comment.