Skip to content

Commit

Permalink
Formatted the demo / example files (#593)
Browse files Browse the repository at this point in the history
Closes #590

Signed-off-by: Martin van Wingerden <martinvw@mtin.nl>
  • Loading branch information
martinvw authored and kaikreuzer committed Dec 3, 2017
1 parent 6eeea37 commit a450b6a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 115 deletions.
34 changes: 17 additions & 17 deletions features/distro-resources/src/main/resources/items/demo.items
Expand Up @@ -25,7 +25,7 @@ Group:Number:AVG Temperature "Avg. Room Temperature [%.1f °C]"
Group:Contact:OR(OPEN, CLOSED) Windows "Open windows [(%d)]" <contact>

/* Lights */
Dimmer Light_GF_Living_Table "Table" (GF_Living, Lights) ["Lighting"]
Dimmer Light_GF_Living_Table "Table" (GF_Living, Lights) ["Lighting"]
Switch Light_GF_Corridor_Ceiling "Ceiling" (GF_Corridor, Lights)
Switch Light_GF_Kitchen_Ceiling "Ceiling" (GF_Kitchen, Lights)
Switch Light_GF_Kitchen_Table "Table" (GF_Kitchen, Lights)
Expand All @@ -43,21 +43,21 @@ Switch Light_FF_Bed_Ceiling "Ceiling" (FF_Bed, Lights)
Switch Light_C_Corridor_Ceiling "Ceiling" (gC, Lights)
Switch Light_C_Staircase "Staircase" (gC, Lights)
Switch Light_C_Washing_Ceiling "Washing" (gC, Lights)
Switch Light_C_Workshop "Workshop" (gC, Lights) ["Lighting"]
Switch Light_C_Workshop "Workshop" (gC, Lights) ["Lighting"]

Switch Light_Garden_Garage "Garage" (Garden, Lights) ["Lighting"]
Switch Light_Garden_Garage "Garage" (Garden, Lights) ["Lighting"]
Switch Light_Garden_Terrace "Terrace" (Garden, Lights)

/* Heating */
Switch Heating_GF_Corridor "Corridor" <heating> (GF_Corridor, Heating)
Switch Heating_GF_Toilet "Toilet" <heating> (GF_Toilet, Heating)
Switch Heating_GF_Living "Livingroom" <heating> (GF_Living, Heating)
Switch Heating_GF_Kitchen "Kitchen" <heating> (GF_Kitchen, Heating)
Switch Heating_GF_Corridor "Corridor" <heating> (GF_Corridor, Heating)
Switch Heating_GF_Toilet "Toilet" <heating> (GF_Toilet, Heating)
Switch Heating_GF_Living "Livingroom" <heating> (GF_Living, Heating)
Switch Heating_GF_Kitchen "Kitchen" <heating> (GF_Kitchen, Heating)

Switch Heating_FF_Bath "Bath" <heating> (FF_Bath, Heating)
Switch Heating_FF_Office "Office" <heating> (FF_Office, Heating)
Switch Heating_FF_Child "Child's Room" <heating> (FF_Child, Heating)
Switch Heating_FF_Bed "Bedroom" <heating> (FF_Bed, Heating)
Switch Heating_FF_Bath "Bath" <heating> (FF_Bath, Heating)
Switch Heating_FF_Office "Office" <heating> (FF_Office, Heating)
Switch Heating_FF_Child "Child's Room" <heating> (FF_Child, Heating)
Switch Heating_FF_Bed "Bedroom" <heating> (FF_Bed, Heating)

/* Rollershutters */
Rollershutter Shutter_GF_Toilet "Toilet" (GF_Toilet, Shutters)
Expand Down Expand Up @@ -111,15 +111,15 @@ String Moon_Phase "Moon Phase" <moon> { ch
/* Demo items */
DateTime CurrentDate "Date [%1$tA, %1$td.%1$tm.%1$tY]" <calendar> { channel="ntp:ntp:demo:dateTime" }
Switch DemoSwitch "Switch"
Dimmer DimmedLight "Dimmer [%d %%]" <slider>
Color RGBLight "RGB Light" <slider>
Dimmer DimmedLight "Dimmer [%d %%]" <slider>
Color RGBLight "RGB Light" <slider>
Rollershutter DemoShutter "Roller Shutter"
Dimmer DemoBlinds "Blinds [%d %%]" <rollershutter>
Number Scene_General "Scene" <sofa>
Number Radio_Station "Radio" <network>
Dimmer DemoBlinds "Blinds [%d %%]" <rollershutter>
Number Scene_General "Scene" <sofa>
Number Radio_Station "Radio" <network>
Dimmer Volume "Volume [%.1f %%]"
Location DemoLocation "Brandenburg Gate Berlin"
Number Wifi_Level "Wifi Level [%d/4]" <signal> (FF_Office)
Number Wifi_Level "Wifi Level [%d/4]" <signal> (FF_Office)
String ImageURL "Image URL [%s]"

Group Thermostat "Thermostat" <temperature> ["Thermostat"]
Expand Down
@@ -1,14 +1,14 @@
// persistence strategies have a name and a definition and are referred to in the "Items" section
Strategies {
// for rrd charts, we need a cron strategy
everyMinute : "0 * * * * ?"
// for rrd charts, we need a cron strategy
everyMinute : "0 * * * * ?"
}

Items {
DemoSwitch,NoOfLights,Window_GF_Toilet,Heating* : strategy = everyChange, everyMinute, restoreOnStartup
// let's only store temperature values in rrd
Temperature*,Weather_Chart* : strategy = everyMinute, restoreOnStartup
DemoSwitch, NoOfLights, Window_GF_Toilet, Heating* : strategy = everyChange, everyMinute, restoreOnStartup
// let's only store temperature values in rrd
Temperature*, Weather_Chart* : strategy = everyMinute, restoreOnStartup
}

// vim: syntax=Xtend
178 changes: 89 additions & 89 deletions features/distro-resources/src/main/resources/rules/demo.rules
Expand Up @@ -11,28 +11,28 @@ val Random random = new Random()
* and posting an updated state on the bus
*/
rule "Dimmed Light"
when
Item DimmedLight received command
then
if ((receivedCommand==INCREASE) || (receivedCommand==DECREASE)) {
var Number percent = 0
if(DimmedLight.state instanceof DecimalType) percent = DimmedLight.state as DecimalType
if(receivedCommand==INCREASE) percent = percent + 5
if(receivedCommand==DECREASE) percent = percent - 5
if(percent<0) percent = 0
if(percent>100) percent = 100
postUpdate(DimmedLight, percent);
}
when
Item DimmedLight received command
then
if ((receivedCommand == INCREASE) || (receivedCommand == DECREASE)) {
var Number percent = 0
if (DimmedLight.state instanceof DecimalType) percent = DimmedLight.state as DecimalType

if (receivedCommand == INCREASE) percent = percent + 5
if (receivedCommand == DECREASE) percent = percent - 5

if (percent < 0) percent = 0
if (percent > 100) percent = 100
postUpdate(DimmedLight, percent);
}
end

rule "Timer Demo"
when
Item Light_GF_Corridor_Ceiling received command
then
if(receivedCommand==ON) {
if(timer===null) {
if (receivedCommand == ON) {
if (timer === null) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusSeconds(10)) [|
sendCommand(Light_GF_Corridor_Ceiling, OFF)
Expand All @@ -41,9 +41,9 @@ then
// subsequent ON command, so reschedule the existing timer
timer.reschedule(now.plusSeconds(10))
}
} else if(receivedCommand==OFF) {
} else if (receivedCommand == OFF) {
// remove any previously scheduled timer
if(timer!==null) {
if (timer !== null) {
timer.cancel
timer = null
}
Expand All @@ -54,113 +54,113 @@ end
* The following rules help initializing the demo items with some helpful states.
*/
rule "Initialize light states"
when
System started
then
Lights?.members.forEach(light|
postUpdate(light, if(Math::random > 0.7) ON else OFF)
)
when
System started
then
Lights?.members.forEach(light|
postUpdate(light, if (Math::random > 0.7) ON else OFF)
)
end

rule "Initialize heating states"
when
System started
then
Heating?.members.forEach(heating|
postUpdate(heating, if(Math::random > 0.8) ON else OFF)
)
postUpdate(Temperature_Setpoint, 22)
when
System started
then
Heating?.members.forEach(heating|
postUpdate(heating, if (Math::random > 0.8) ON else OFF)
)
postUpdate(Temperature_Setpoint, 22)
end

rule "Initialize contact states"
when
System started
then
Windows?.members.forEach(window|
postUpdate(window, if(Math::random > 0.5) OPEN else CLOSED)
)
when
System started
then
Windows?.members.forEach(window|
postUpdate(window, if (Math::random > 0.5) OPEN else CLOSED)
)
end

rule "Initialize Location"
when
System started
then
DemoLocation.postUpdate(new PointType("52.5200066,13.4049540"))
when
System started
then
DemoLocation.postUpdate(new PointType("52.5200066,13.4049540"))
end

rule "Set random room temperatures"
when
System started or
Time cron "0 0/5 * * * ?"
then
Temperature?.members.forEach(temperature|
postUpdate(temperature, 20.0 + (25.0 - (Math::random * 50.0).intValue) / 10.0)
)
when
System started or
Time cron "0 0/5 * * * ?"
then
Temperature?.members.forEach(temperature|
postUpdate(temperature, 20.0 + (25.0 - (Math::random * 50.0).intValue) / 10.0)
)
end

rule "Set daily max and min temperature"
when
Item Weather_Temperature changed or
Time cron "0 0 0 * * ?" or
System started
Item Weather_Temperature changed or
Time cron "0 0 0 * * ?" or
System started
then
val max = Weather_Temperature.maximumSince(now.withTimeAtStartOfDay)
val min = Weather_Temperature.minimumSince(now.withTimeAtStartOfDay)
if( max !== null && min !== null) {
postUpdate(Weather_Temp_Max, max.state)
postUpdate(Weather_Temp_Min, min.state)
}
val max = Weather_Temperature.maximumSince(now.withTimeAtStartOfDay)
val min = Weather_Temperature.minimumSince(now.withTimeAtStartOfDay)
if (max !== null && min !== null) {
postUpdate(Weather_Temp_Max, max.state)
postUpdate(Weather_Temp_Min, min.state)
}
end

// Creates an item that stores the last update time of this item
rule "Records last weather update time"
when
Item Weather_Temperature received update
Item Weather_Temperature received update
then
postUpdate(Weather_LastUpdate, new DateTimeType())
postUpdate(Weather_LastUpdate, new DateTimeType())
end

rule "Set random wifi variations"
when
System started or
Time cron "/20 * * * * ?"
then
postUpdate(Wifi_Level, (Math::random * 4.0).intValue)
when
System started or
Time cron "/20 * * * * ?"
then
postUpdate(Wifi_Level, (Math::random * 4.0).intValue)
end

rule "Set random image URLs"
when
Time cron "/10 * * * * ?"
then
val url = urlList.get(random.nextInt(urlList.length))
val res = resList.get(random.nextInt(resList.length))
when
Time cron "/10 * * * * ?"
then
val url = urlList.get(random.nextInt(urlList.length))
val res = resList.get(random.nextInt(resList.length))

postUpdate(ImageURL, url + "/" + res)
postUpdate(ImageURL, url + "/" + res)
end

rule "Volume"
when
Item Volume received command
then
if(receivedCommand instanceof PercentType) {
setMasterVolume(receivedCommand)
} else {
if(receivedCommand==INCREASE) increaseMasterVolume(20)
if(receivedCommand==DECREASE) decreaseMasterVolume(20)
}
when
Item Volume received command
then
if (receivedCommand instanceof PercentType) {
setMasterVolume(receivedCommand)
} else {
if (receivedCommand == INCREASE) increaseMasterVolume(20)
if (receivedCommand == DECREASE) decreaseMasterVolume(20)
}
end

rule "Select Radio Station"
when
Item Radio_Station received command
then
switch(receivedCommand) {
case 0 : playStream(null)
case 1 : playStream("http://metafiles.gl-systemhaus.de/hr/hr3_2.m3u")
case 2 : playStream("http://mp3-live.swr3.de/swr3_m.m3u")
case 3 : playStream("http://edge.live.mp3.mdn.newmedia.nacamar.net/radioffh/livestream.mp3.m3u")
case 4 : playStream("http://stream.laut.fm/club93")
}
when
Item Radio_Station received command
then
switch(receivedCommand) {
case 0 : playStream(null)
case 1 : playStream("http://metafiles.gl-systemhaus.de/hr/hr3_2.m3u")
case 2 : playStream("http://mp3-live.swr3.de/swr3_m.m3u")
case 3 : playStream("http://edge.live.mp3.mdn.newmedia.nacamar.net/radioffh/livestream.mp3.m3u")
case 4 : playStream("http://stream.laut.fm/club93")
}
end

// vim: syntax=Xtend
@@ -1,6 +1,8 @@
yahooweather:weather:berlin [ location=638242 ]
astro:sun:home [ geolocation="52.5200066,13.4049540", interval=60 ]
astro:moon:home [ geolocation="52.5200066,13.4049540", interval=60 ]
ntp:ntp:demo [ hostname="nl.pool.ntp.org", refreshInterval=60, refreshNtp=30 ]

astro:sun:home [ geolocation="52.5200066,13.4049540", interval=60 ]
astro:moon:home [ geolocation="52.5200066,13.4049540", interval=60 ]

ntp:ntp:demo [ hostname="nl.pool.ntp.org", refreshInterval=60, refreshNtp=30 ]

// vim: syntax=Xtend

0 comments on commit a450b6a

Please sign in to comment.