mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Initial Commit
This commit is contained in:
73
zwave/lantern-datamodel-zwave/pom.xml
Normal file
73
zwave/lantern-datamodel-zwave/pom.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lanternsoftware.services</groupId>
|
||||
<artifactId>lantern-datamodel-zwave</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<name>lantern-datamodel-zwave</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanternsoftware.util</groupId>
|
||||
<artifactId>lantern-util-dao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
<phase>compile</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<optimize>true</optimize>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<index>true</index>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.lanternsoftware.datamodel.zwave;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable
|
||||
public class Switch {
|
||||
private String room;
|
||||
private String name;
|
||||
private int nodeId;
|
||||
private int level;
|
||||
private boolean primary;
|
||||
private boolean multilevel;
|
||||
private boolean hold;
|
||||
private String thermostatSource;
|
||||
private ThermostatMode thermostatMode;
|
||||
private int lowLevel;
|
||||
private List<SwitchSchedule> schedule;
|
||||
|
||||
public Switch() {
|
||||
}
|
||||
|
||||
public Switch(String _room, String _name, int _nodeId, boolean _primary, boolean _multilevel, String _thermostatSource, int _lowLevel) {
|
||||
this(_room, _name, _nodeId, 0, _primary, _multilevel, false, _thermostatSource, _lowLevel, null);
|
||||
}
|
||||
|
||||
public Switch(String _room, String _name, int _nodeId, int _level, boolean _primary, boolean _multilevel, boolean _hold, String _thermostatSource, int _lowLevel, List<SwitchSchedule> _schedule) {
|
||||
room = _room;
|
||||
name = _name;
|
||||
nodeId = _nodeId;
|
||||
level = _level;
|
||||
primary = _primary;
|
||||
multilevel = _multilevel;
|
||||
hold = _hold;
|
||||
thermostatSource = _thermostatSource;
|
||||
lowLevel = _lowLevel;
|
||||
schedule = _schedule;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public void setRoom(String _room) {
|
||||
room = _room;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
|
||||
public int getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(int _nodeId) {
|
||||
nodeId = _nodeId;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int _level) {
|
||||
level = _level;
|
||||
}
|
||||
|
||||
public boolean isPrimary() {
|
||||
return primary;
|
||||
}
|
||||
|
||||
public void setPrimary(boolean _primary) {
|
||||
primary = _primary;
|
||||
}
|
||||
|
||||
public boolean isMultilevel() {
|
||||
return multilevel;
|
||||
}
|
||||
|
||||
public void setMultilevel(boolean _multilevel) {
|
||||
multilevel = _multilevel;
|
||||
}
|
||||
|
||||
public boolean isHold() {
|
||||
return hold;
|
||||
}
|
||||
|
||||
public void setHold(boolean _hold) {
|
||||
hold = _hold;
|
||||
}
|
||||
|
||||
public String getThermostatSource() {
|
||||
return thermostatSource;
|
||||
}
|
||||
|
||||
public void setThermostatSource(String _thermostatSource) {
|
||||
thermostatSource = _thermostatSource;
|
||||
}
|
||||
|
||||
public boolean isThermostat() {
|
||||
return NullUtils.isNotEmpty(thermostatSource) && (nodeId < 100);
|
||||
}
|
||||
|
||||
public boolean isThermometer() {
|
||||
return isUrlThermostat() && (nodeId > 99);
|
||||
}
|
||||
|
||||
public boolean isUrlThermostat() {
|
||||
return NullUtils.makeNotNull(thermostatSource).startsWith("http");
|
||||
}
|
||||
|
||||
public boolean isZWaveThermostat() {
|
||||
return NullUtils.isEqual(thermostatSource, "ZWAVE");
|
||||
}
|
||||
|
||||
public ThermostatMode getThermostatMode() {
|
||||
return thermostatMode;
|
||||
}
|
||||
|
||||
public void setThermostatMode(ThermostatMode _thermostatMode) {
|
||||
thermostatMode = _thermostatMode;
|
||||
}
|
||||
|
||||
public int getLowLevel() {
|
||||
return lowLevel;
|
||||
}
|
||||
|
||||
public void setLowLevel(int _lowLevel) {
|
||||
lowLevel = _lowLevel;
|
||||
}
|
||||
|
||||
public List<SwitchSchedule> getSchedule() {
|
||||
return schedule;
|
||||
}
|
||||
|
||||
public void setSchedule(List<SwitchSchedule> _schedule) {
|
||||
schedule = _schedule;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.lanternsoftware.datamodel.zwave;
|
||||
|
||||
|
||||
import com.lanternsoftware.util.DateUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@DBSerializable
|
||||
public class SwitchSchedule {
|
||||
private int dayOfWeek;
|
||||
private int timeOfDay;
|
||||
private int minutesPerHour;
|
||||
private int level;
|
||||
|
||||
public SwitchSchedule() {
|
||||
}
|
||||
|
||||
public SwitchSchedule(int _minutesPerHour) {
|
||||
minutesPerHour = _minutesPerHour;
|
||||
}
|
||||
|
||||
public SwitchSchedule(int _dayOfWeek, int _timeOfDay, int _level) {
|
||||
dayOfWeek = _dayOfWeek;
|
||||
timeOfDay = _timeOfDay;
|
||||
level = _level;
|
||||
}
|
||||
|
||||
public SwitchSchedule(int _dayOfWeek, int _hour, int _minute, int _level) {
|
||||
dayOfWeek = _dayOfWeek;
|
||||
setTimeOfDay(_hour, _minute);
|
||||
level = _level;
|
||||
}
|
||||
|
||||
public SwitchSchedule(int _dayOfWeek, int _hour, int _minute, int _second, int _level) {
|
||||
dayOfWeek = _dayOfWeek;
|
||||
setTimeOfDay(_hour, _minute, _second);
|
||||
level = _level;
|
||||
}
|
||||
|
||||
public int getDayOfWeek() {
|
||||
return dayOfWeek;
|
||||
}
|
||||
|
||||
public void setDayOfWeek(int _dayOfWeek) {
|
||||
dayOfWeek = _dayOfWeek;
|
||||
}
|
||||
|
||||
public int getTimeOfDay() {
|
||||
return timeOfDay;
|
||||
}
|
||||
|
||||
public void setTimeOfDay(int _timeOfDayInSeconds) {
|
||||
timeOfDay = _timeOfDayInSeconds;
|
||||
}
|
||||
|
||||
public void setTimeOfDay(int _hour, int _minute) {
|
||||
timeOfDay = (_hour * 3600) + (_minute * 60);
|
||||
}
|
||||
public void setTimeOfDay(int _hour, int _minute, int _second) {
|
||||
timeOfDay = (_hour * 3600) + (_minute * 60) + _second;
|
||||
}
|
||||
|
||||
public int getMinutesPerHour() {
|
||||
return minutesPerHour;
|
||||
}
|
||||
|
||||
public void setMinutesPerHour(int _minutesPerHour) {
|
||||
minutesPerHour = _minutesPerHour;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int _level) {
|
||||
level = _level;
|
||||
}
|
||||
|
||||
public int hour() {
|
||||
return timeOfDay/3600;
|
||||
}
|
||||
|
||||
public int minute() {
|
||||
return (timeOfDay/60)%60;
|
||||
}
|
||||
|
||||
public int second() {
|
||||
return timeOfDay%60;
|
||||
}
|
||||
|
||||
private boolean isOn() {
|
||||
return GregorianCalendar.getInstance().get(Calendar.MINUTE) < minutesPerHour;
|
||||
}
|
||||
|
||||
public SwitchTransition getNextTransition(Switch _switch, TimeZone _tz) {
|
||||
if (minutesPerHour > 0) {
|
||||
Date dt = DateUtils.getStartOfHour(_tz);
|
||||
Date transition = DateUtils.addMinutes(dt, minutesPerHour);
|
||||
if (new Date().before(transition))
|
||||
return new SwitchTransition(_switch, transition, 0);
|
||||
return new SwitchTransition(_switch, DateUtils.getEndOfHour(_tz), level == 0?255:level);
|
||||
}
|
||||
Date now = new Date();
|
||||
Calendar cal = DateUtils.toCalendar(now, _tz);
|
||||
cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
|
||||
cal.set(Calendar.HOUR_OF_DAY, hour());
|
||||
cal.set(Calendar.MINUTE, minute());
|
||||
cal.set(Calendar.SECOND, second());
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
if (cal.getTimeInMillis() <= now.getTime())
|
||||
cal.add(Calendar.DAY_OF_MONTH, 7);
|
||||
return new SwitchTransition(_switch, cal.getTime(), level);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.lanternsoftware.datamodel.zwave;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SwitchTransition {
|
||||
private final Switch sw;
|
||||
private final Date transitionTime;
|
||||
private final int level;
|
||||
|
||||
SwitchTransition(Switch _sw, Date _transitionTime, int _level) {
|
||||
sw = _sw;
|
||||
transitionTime = _transitionTime;
|
||||
level = _level;
|
||||
}
|
||||
|
||||
public Switch getSwitch() {
|
||||
return sw;
|
||||
}
|
||||
|
||||
public Date getTransitionTime() {
|
||||
return transitionTime;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.lanternsoftware.datamodel.zwave;
|
||||
|
||||
public enum ThermostatMode {
|
||||
OFF((byte)0, "Off"),
|
||||
HEAT((byte)1, "Heat"),
|
||||
COOL((byte)2, "Cool"),
|
||||
AUXILIARY((byte)4, "E-Heat");
|
||||
|
||||
public final byte data;
|
||||
public final String display;
|
||||
|
||||
ThermostatMode(byte _data, String _display) {
|
||||
data = _data;
|
||||
display = _display;
|
||||
}
|
||||
|
||||
public static ThermostatMode fromByte(byte _bt) {
|
||||
for (ThermostatMode mode : values()) {
|
||||
if (mode.data == _bt)
|
||||
return mode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.lanternsoftware.datamodel.zwave;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable(autogen = false)
|
||||
public class ZWaveConfig {
|
||||
@PrimaryKey
|
||||
private int accountId;
|
||||
private List<Switch> switches;
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public List<Switch> getSwitches() {
|
||||
return switches;
|
||||
}
|
||||
|
||||
public void setSwitches(List<Switch> _switches) {
|
||||
switches = _switches;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.lanternsoftware.datamodel.zwave.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.zwave.SwitchSchedule;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SwitchScheduleSerializer extends AbstractDaoSerializer<SwitchSchedule>
|
||||
{
|
||||
@Override
|
||||
public Class<SwitchSchedule> getSupportedClass()
|
||||
{
|
||||
return SwitchSchedule.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(SwitchSchedule _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("day_of_week", _o.getDayOfWeek());
|
||||
d.put("time_of_day", _o.getTimeOfDay());
|
||||
d.put("minutes_per_hour", _o.getMinutesPerHour());
|
||||
d.put("level", _o.getLevel());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwitchSchedule fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
SwitchSchedule o = new SwitchSchedule();
|
||||
o.setDayOfWeek(DaoSerializer.getInteger(_d, "day_of_week"));
|
||||
o.setTimeOfDay(DaoSerializer.getInteger(_d, "time_of_day"));
|
||||
o.setMinutesPerHour(DaoSerializer.getInteger(_d, "minutes_per_hour"));
|
||||
o.setLevel(DaoSerializer.getInteger(_d, "level"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.lanternsoftware.datamodel.zwave.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.zwave.Switch;
|
||||
import com.lanternsoftware.datamodel.zwave.SwitchSchedule;
|
||||
import com.lanternsoftware.datamodel.zwave.ThermostatMode;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SwitchSerializer extends AbstractDaoSerializer<Switch>
|
||||
{
|
||||
@Override
|
||||
public Class<Switch> getSupportedClass()
|
||||
{
|
||||
return Switch.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(Switch _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("room", _o.getRoom());
|
||||
d.put("name", _o.getName());
|
||||
d.put("node_id", _o.getNodeId());
|
||||
d.put("level", _o.getLevel());
|
||||
d.put("primary", _o.isPrimary());
|
||||
d.put("multilevel", _o.isMultilevel());
|
||||
d.put("hold", _o.isHold());
|
||||
d.put("thermostat_source", _o.getThermostatSource());
|
||||
d.put("thermostat_mode", DaoSerializer.toEnumName(_o.getThermostatMode()));
|
||||
d.put("low_level", _o.getLowLevel());
|
||||
d.put("schedule", DaoSerializer.toDaoEntities(_o.getSchedule(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Switch fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
Switch o = new Switch();
|
||||
o.setRoom(DaoSerializer.getString(_d, "room"));
|
||||
o.setName(DaoSerializer.getString(_d, "name"));
|
||||
o.setNodeId(DaoSerializer.getInteger(_d, "node_id"));
|
||||
o.setLevel(DaoSerializer.getInteger(_d, "level"));
|
||||
o.setPrimary(DaoSerializer.getBoolean(_d, "primary"));
|
||||
o.setMultilevel(DaoSerializer.getBoolean(_d, "multilevel"));
|
||||
o.setHold(DaoSerializer.getBoolean(_d, "hold"));
|
||||
o.setThermostatSource(DaoSerializer.getString(_d, "thermostat_source"));
|
||||
o.setThermostatMode(DaoSerializer.getEnum(_d, "thermostat_mode", ThermostatMode.class));
|
||||
o.setLowLevel(DaoSerializer.getInteger(_d, "low_level"));
|
||||
o.setSchedule(DaoSerializer.getList(_d, "schedule", SwitchSchedule.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.lanternsoftware.datamodel.zwave.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.zwave.Switch;
|
||||
import com.lanternsoftware.datamodel.zwave.ZWaveConfig;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ZWaveConfigSerializer extends AbstractDaoSerializer<ZWaveConfig>
|
||||
{
|
||||
@Override
|
||||
public Class<ZWaveConfig> getSupportedClass()
|
||||
{
|
||||
return ZWaveConfig.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(ZWaveConfig _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("_id", String.valueOf(_o.getAccountId()));
|
||||
d.put("switches", DaoSerializer.toDaoEntities(_o.getSwitches(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZWaveConfig fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
ZWaveConfig o = new ZWaveConfig();
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "_id"));
|
||||
o.setSwitches(DaoSerializer.getList(_d, "switches", Switch.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
com.lanternsoftware.datamodel.zwave.dao.SwitchScheduleSerializer
|
||||
com.lanternsoftware.datamodel.zwave.dao.SwitchSerializer
|
||||
com.lanternsoftware.datamodel.zwave.dao.ZWaveConfigSerializer
|
||||
Reference in New Issue
Block a user