Renamed some DeviceData classes, added additional data classes also and better handling in zigbee

This commit is contained in:
Ziver Koc 2021-10-02 19:42:23 +02:00
parent dc200294be
commit 3edea58f8c
18 changed files with 275 additions and 45 deletions

View file

@ -5,4 +5,10 @@ package se.hal.intf;
*/
public interface HalEventConfig extends HalDeviceConfig {
/**
* @return true if this event device is only a reporting data and do not accept writing/changing the data from Hal.
*/
default boolean isReadOnly() {
return false;
}
}

View file

@ -47,9 +47,9 @@ public class EventOverviewWebPage extends HalWebPage {
// change event data
OnOffEventData eventData = new OnOffEventData();
if (request.containsKey("enabled") && "on".equals(request.get("enabled")))
eventData.turnOn();
eventData.setOn();
else
eventData.turnOff();
eventData.setOff();
logger.info("Modifying Event(" + id + ") state: " + eventData.toString());
Event event = Event.getEvent(db, id);

View file

@ -2,13 +2,14 @@ package se.hal.struct.devicedata;
import se.hal.intf.HalSensorData;
public class LightSensorData extends HalSensorData {
public class IlluminanceSensorData extends HalSensorData {
private double lux;
public LightSensorData(){}
public LightSensorData(double lux, long timestamp){
public IlluminanceSensorData(){}
public IlluminanceSensorData(double lux, long timestamp){
this.lux = lux;
this.setTimestamp(timestamp);
}
@ -16,7 +17,7 @@ public class LightSensorData extends HalSensorData {
@Override
public String toString(){
return lux+" lux";
return lux + " lux";
}
// ----------------------------------------
@ -32,10 +33,10 @@ public class LightSensorData extends HalSensorData {
}
/**
* @param lux set the light intensity in lux
* @param data set the light intensity in lux
*/
@Override
public void setData(double lux) {
this.lux = lux;
public void setData(double data) {
this.lux = data;
}
}

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2015 Ziver
*
* 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.
*/
package se.hal.struct.devicedata;
import se.hal.intf.HalEventData;
public class OccupancyEventData extends HalEventData {
private boolean isOccupied;
public OccupancyEventData() { }
public OccupancyEventData(boolean isOccupied, long timestamp) {
this.isOccupied = isOccupied;
this.setTimestamp(timestamp);
}
public void setOccupied(){
this.isOccupied = true;
}
public void setOccupied(boolean isOccupied){
this.isOccupied = isOccupied;
}
public void setUnoccupied(){
this.isOccupied = false;
}
public void toggle(){
isOccupied = !isOccupied;
}
public boolean isOccupied(){
return isOccupied;
}
@Override
public String toString(){
return isOccupied ? "Occupied" : "Unoccupied";
}
// ----------------------------------------
// Storage methods
// ----------------------------------------
@Override
public double getData() {
return (isOccupied ? 1.0 : 0.0);
}
@Override
public void setData(double data) {
this.isOccupied = data > 0;
}
}

View file

@ -37,10 +37,10 @@ public class OnOffEventData extends HalEventData {
}
public void turnOn(){
public void setOn(){
isOn = true;
}
public void turnOff(){
public void setOff(){
isOn = false;
}
public void toggle(){
@ -66,7 +66,7 @@ public class OnOffEventData extends HalEventData {
}
@Override
public void setData(double enabled) {
this.isOn = enabled > 0;
public void setData(double data) {
this.isOn = data > 0;
}
}

View file

@ -36,10 +36,10 @@ public class OpenClosedEventData extends HalEventData {
this.setTimestamp(timestamp);
}
public void open(){
public void setOpen(){
isOpen = true;
}
public void close(){
public void setClose(){
isOpen = false;
}
public void toggle(){
@ -65,7 +65,7 @@ public class OpenClosedEventData extends HalEventData {
}
@Override
public void setData(double enabled) {
this.isOpen = enabled > 0;
public void setData(double data) {
this.isOpen = data > 0;
}
}