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

Commit

Permalink
Polymer binary switch support
Browse files Browse the repository at this point in the history
The polymer client now supports binary switches
  • Loading branch information
wburgers committed Jan 5, 2015
1 parent 2482764 commit 9290006
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Client/Polymer Client/custom_components/device-item.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-slider/paper-slider.html">
<link rel="import" href="../bower_components/paper-toggle-button/paper-toggle-button.html">

<polymer-element name="device-item">
<template>
Expand All @@ -18,6 +19,12 @@
float: left;
margin: 10px;
}
paper-toggle-button::shadow paper-radio-button::shadow #onRadio {
background-color: #4285f4;
}
paper-toggle-button::shadow #toggleBar[checked] {
background-color: #4285f4;
}
</style>
<div layout horizontal center>
<h4>{{device.Name}}</h4>
Expand All @@ -31,6 +38,12 @@ <h4>{{device.Name}}</h4>
on-change="{{sliderChanged}}">
</paper-slider>
</template>
<template if="{{device.Type === 'Binary Power Switch'}}">
<paper-toggle-button
id="toggle"
on-change="{{toggleChanged}}"
></paper-toggle-button>
</template>
<div class="names">
<template if="{{device.Values['Battery Level']}}">
<span block>Battery Level</span>
Expand All @@ -49,10 +62,31 @@ <h4>{{device.Name}}</h4>
publish: {
device: {},
},
observe: {
'device.Values.Switch': 'toggleChange',
},
sliderChanged: function(event, detail, sender) {
var commandstring = "SETNODE~"+this.device.ID+"~Level="+sender.value;
this.fire('send-command',{command:commandstring});
},
toggleChanged: function(event, detail, sender) {
var checked = sender.checked === true ? 1 : 0;
var commandstring = "SETNODE~"+this.device.ID+"~Switch="+checked;
this.fire('send-command',{command:commandstring});
},
toggleChange: function(oldValue, newValue) {
if(newValue == "True") {
this.$.toggle.checked = true;
}
else {
this.$.toggle.checked = false;
}
},
ready: function() {
if(this.device.Values.Switch == "True") {
this.$.toggle.checked = true;
}
}
});
</script>
</polymer-element>

0 comments on commit 9290006

Please sign in to comment.