Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Added option to ratelimit device updates #44

Open
wants to merge 1 commit into
base: release_0.1.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions device-config-schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ module.exports = {
description: "Auto reset time in milliseconds"
type: "integer"
default: 1000
rateLimit:
description: "Limit data updates to on once every x milliseconds (0 for no limit)"
type: "integer"
default: 0
},
RaspBeeGroupScenes: {
title: "RaspBeeScenes"
Expand Down
10 changes: 9 additions & 1 deletion raspbee.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ module.exports = (env) ->
@attributes = {}
@actions = {}
@_resetTimeout = null
@_rateLimitTimeout = null
@_rateLimited = false
@CmdMap = []

if @config.supportsBattery
Expand Down Expand Up @@ -471,7 +473,12 @@ module.exports = (env) ->

super()
myRaspBeePlugin.on "event", (data) =>
if data.id in @sensorIDs and data.resource is "sensors" and data.event is "changed"
if data.id in @sensorIDs and data.resource is "sensors" and data.event is "changed" and !@_rateLimited
if @config.rateLimit > 0
@_rateLimited = true
@_rateLimitTimeout = setTimeout ( =>
@_rateLimited = false
), @config.rateLimit
@_updateAttributes data

myRaspBeePlugin.on "config", () =>
Expand Down Expand Up @@ -535,6 +542,7 @@ module.exports = (env) ->

destroy: ->
clearTimeout(@_resetTimeout) if @_resetTimeout?
clearTimeout(@_rateLimitTimeout) if @_rateLimitTimeout?
super()

_setBattery: (value) ->
Expand Down