Skip to content

Commit

Permalink
option to choose local or GMT timezone and some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DheerajKhajuria committed Jan 1, 2017
1 parent acf7ae9 commit d856054
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 9 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
6 changes: 5 additions & 1 deletion MySensors-config-schema.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
protocols:
description: "MySensors protrocol version"
type: "string"
default: "1.4.1"
default: "1.5.1"
metric:
description: "(M)etric or (I)mperal"
type: "string"
Expand All @@ -33,4 +33,8 @@ module.exports = {
description: "Mysensors starting node id"
type: "number"
default: 1
time:
description: "use 'local' or 'utc' time"
type: "string"
default: "local"
}
18 changes: 10 additions & 8 deletions MySensors.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ module.exports = (env) ->
constructor: (framework,config) ->
@config = config
@framework = framework
assert @config.time in ["utc", "local"]
assert @config.driver in ["serialport", "gpio"]

@timeOffset = 0
if @config.time is "local"
@timeOffset = ((new Date()).getTimezoneOffset() * 60 )
env.logger.debug "<- TimeOffset ", @timeOffset
# setup a new driver
switch @config.driver
when "serialport"
Expand Down Expand Up @@ -267,7 +273,7 @@ module.exports = (env) ->

_rfsendTime: (destination,sensor) ->
date = new Date()
payload = Math.floor( ( date.getTime() ) / 1000 ) - ( date.getTimezoneOffset() * 60 )
payload = Math.floor( ( date.getTime() ) / 1000 ) - @timeOffset
datas =
{
"destination": destination,
Expand Down Expand Up @@ -371,7 +377,6 @@ module.exports = (env) ->

init: (app, @framework, @config) =>
@board = new Board(@framework, @config)

@board.connect().then( =>
env.logger.info("Connected to MySensors Gateway.")
)
Expand Down Expand Up @@ -1111,10 +1116,6 @@ module.exports = (env) ->
calculatePower:(result) ->
currdate = new Date()

if currdate > new Date(currdate.getFullYear(), currdate.getMonth() + 1, 1)
@_kwh = 0
@_rate = 0

diffTime = currdate - @kWhlastTime[result.sensor]

@_watt[result.sensor] = Math.floor(parseInt(result.value))
Expand Down Expand Up @@ -1543,7 +1544,7 @@ module.exports = (env) ->
@board._rfWrite(datas)
)

@rfValueEventHandler = ( (result) =>
@rfValueEventHandlerx = ( (result) =>
if result.sender is @config.nodeid and result.type is V_PERCENTAGE and result.sensor is @config.sensorid
state = (if parseInt(result.value) is 0 then off else on)
dimlevel = (result.value)
Expand Down Expand Up @@ -1574,6 +1575,7 @@ module.exports = (env) ->
"ack" : 1
}
@board._rfWrite(datas).then ( () =>
if level in [0-100]
@_setDimlevel(level)
)

Expand Down Expand Up @@ -2024,7 +2026,7 @@ module.exports = (env) ->
@board.removeListener "rfValue", @rfValueEventHandler
@board.removeListener "rfbattery", @rfbatteryEventHandler
super()

_setAttribute: (attributeName, value) ->
@attributeValue[attributeName] = value
@emit attributeName, value
Expand Down
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified device-config-schema.coffee
100644 → 100755
Empty file.
Empty file modified icon.svg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified package.json
100644 → 100755
Empty file.
Empty file modified serialport.coffee
100644 → 100755
Empty file.
Empty file modified test-MySensors.coffee
100644 → 100755
Empty file.

0 comments on commit d856054

Please sign in to comment.