Add billing rates and track cost for all energy readings.

This commit is contained in:
MarkBryanMilligan
2021-08-03 16:47:28 -05:00
parent 8221e8ebd5
commit 8d09ac39f2
26 changed files with 739 additions and 148 deletions

View File

@@ -286,7 +286,7 @@ public class ZWaveApp {
}
public void fireSwitchLevelEvent(Switch _sw) {
if (NullUtils.isEmpty(config.getRulesUrl()))
if (NullUtils.isEmpty(config.getRulesUrl()) || _sw.isSuppressEvents())
return;
Event event = new Event();
event.setEventDescription(_sw.getFullDisplay() + " set to " + _sw.getLevel());
@@ -325,7 +325,7 @@ public class ZWaveApp {
relayController.setRelay(sw.getGpioPin(), sw.getLowLevel() > 0);
}
}, 250);
} else {
} else if (!sw.isSecurity()){
setGroupSwitchLevel(sw, _level);
}
}
@@ -351,7 +351,7 @@ public class ZWaveApp {
}
public void updateSwitch(Switch _sw) {
logger.info("Received update for switch {} level {}", _sw.getFullDisplay(), _sw.getLevel());
logger.info("Received update for switch {} {} level {}", _sw.getNodeId(), _sw.getFullDisplay(), _sw.getLevel());
Switch sw = CollectionUtils.filterOne(config.getSwitches(), _s->_s.getNodeId() == _sw.getNodeId());
if (sw != null) {
sw.setLevel( _sw.getLevel());
@@ -395,6 +395,7 @@ public class ZWaveApp {
peers.remove(config.getUrl());
for (String peer : peers) {
for (Switch sw : modified) {
logger.info("Sending update for switch {} {} level {} to {}", sw.getNodeId(), sw.getFullDisplay(), sw.getLevel(), peer);
HttpPost post = new HttpPost(peer + "/switch/" + sw.getNodeId());
post.setHeader("auth_code", authCode);
post.setEntity(new ByteArrayEntity(DaoSerializer.toZipBson(sw)));

View File

@@ -1,6 +1,7 @@
package com.lanternsoftware.zwave.security;
import com.lanternsoftware.datamodel.zwave.Switch;
import com.lanternsoftware.util.concurrency.ConcurrencyUtils;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
@@ -11,11 +12,16 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SecurityController {
protected static final Logger LOG = LoggerFactory.getLogger(SecurityController.class);
private final Map<Integer, GpioPinDigitalInput> pins = new HashMap<>();
private final Map<Integer, Boolean> pinEvents = new HashMap<>();
private final ExecutorService executor = Executors.newFixedThreadPool(2);
private int eventIdx = 0;
public boolean isOpen(int _pin) {
GpioPinDigitalInput pin = getPin(_pin);
@@ -25,7 +31,24 @@ public class SecurityController {
public void listen(Switch _sw, SecurityListener _listener) {
GpioPinDigitalInput pin = getPin(_sw.getGpioPin());
if (pin != null)
pin.addListener((GpioPinListenerDigital) _event -> _listener.onStateChanged(_sw.getNodeId(), _event.getState().isHigh()));
pin.addListener((GpioPinListenerDigital) _event -> {
synchronized (pinEvents) {
eventIdx++;
LOG.info("state change from gpio, event {} pin {} to {}", eventIdx, _sw.getGpioPin(), _event.getState().isHigh());
pinEvents.put(_sw.getGpioPin(), _event.getState().isHigh());
}
executor.submit(()->{
ConcurrencyUtils.sleep(500);
Boolean high;
synchronized (pinEvents) {
high = pinEvents.remove(_sw.getGpioPin());
}
LOG.info("handling event {} pin {} most recent event is {}", eventIdx, _sw.getGpioPin(), high);
if (high == null)
return;
_listener.onStateChanged(_sw.getNodeId(), high);
});
});
}
private GpioPinDigitalInput getPin(int _pin) {
@@ -47,6 +70,7 @@ public class SecurityController {
pin.removeAllListeners();
}
pins.clear();
executor.shutdownNow();
GpioFactory.getInstance().shutdown();
}
}