Skip to content

Commit

Permalink
V05 Implemented Promisses and Added LightSearch & Group Modifiers
Browse files Browse the repository at this point in the history
Implemented Promisses by returning JQuery Promisses (Deffereds)
Declared local variables where applicable, cleaning up global namespace
polution
Added LightsSearchForNew and LightsGetNew and LightSetName
Added GroupCreate GroupSetName GroupSetLights GroupSetAttributes
GroupDelete
  These need more testing ;-)
  • Loading branch information
ArndBrugman committed Jan 18, 2014
1 parent 1fa3cf9 commit 47951c8
Show file tree
Hide file tree
Showing 2 changed files with 248 additions and 121 deletions.
103 changes: 60 additions & 43 deletions HUEMediate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,34 @@
<script src="../HUEPI.js" type="text/javascript"></script>

<style type="text/css">
html, body, .ui-mobile, .ui-mobile-viewport, .ui-page
{
html, body, .ui-mobile, .ui-mobile-viewport, .ui-page {
width: 100%;
height: 100%;
background:#000000;
border: 0px;
color: #ffffff;
}

#container {
width: 100%;
//height: 100%;
}

.ui-footer
{
.ui-footer {
background: #000000;
border: 0px;
color: #ffffff;
position: fixed;
width: 100%;
//z-index: 999;
}
.ui-slider-track {
margin-left: 15px;
max-width: 320px;
}
#feetupbutton, #onbutton, #offbutton,
#relaxbutton, #energizebutton, #concentratebutton, #readingbutton {
min-width: 64px;
max-width: 128px;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -94,52 +99,64 @@
{
MyHue.Username = "085efe879ee3ed83c04efc28a0da03d3";

if (MyHue.BridgeIP === "")
{
$("#HUEStatus").text("Trying to Discover HUE Bridge via HUE Portal");
MyHue.PortalDiscoverLocalBridges();
setTimeout("DiscoverBridgeAndTryWhitelisting()", 100);
} else
{
$("#HUEBridgeIP").text("Bridge IP: " + MyHue.BridgeIP);
MyHue.BridgeGet();
if (MyHue.BridgeName !== "") {
$("#HUEBridgeName").text("Bridge Name " + MyHue.BridgeName);
}
if (!MyHue.UsernameWhitelisted)
{
MyHue.BridgeCreateUser();
$("#HUEStatus").text("Checking Whitelist, If this takes longer than 5 seconds: please press connect button on Bridge.");
setTimeout("DiscoverBridgeAndTryWhitelisting()", 500);
} else
{
$("#HUEStatus").text("Found Bridge and Whitelisted, so able to Set Lights and Groups.");
$("#HUEInfoBar").hide("slow");
MyHue.GroupOn(0);
MyHue.GroupEffectNone(0);
}
}
$("#HUEStatus").text("Trying to Discover HUE Bridge via HUE Portal");
MyHue.PortalDiscoverLocalBridges().then(function GetBridgeConfig() {
MyHue.BridgeGet().then(function EnsureWhitelisting() {
$("#HUEBridgeIP").text("Bridge IP: " + MyHue.BridgeIP);
if (!MyHue.UsernameWhitelisted) {
$("#HUEStatus").text("Please press connect button on the Hue Bridge");
MyHue.BridgeCreateUser().then(function ReReadBridgeConfiguration() {
setTimeout(GetBridgeConfig, 1000);
}, function UnableToCreateUseronBridge() {
$("#HUEStatus").text("Unable to Create User on Bridge");
});
} else {
$("#HUEBridgeName").text("Bridge Name " + MyHue.BridgeName);
$("#HUEStatus").text("Found Bridge and Whitelisted, so able to Set Lights and Groups");
$("#HUEInfoBar").hide("slow");
MyHue.GroupOn(0);
MyHue.GroupEffectNone(0);
StatusHeartbeat();
}
}, function UnableToRetreiveBridgeConfiguration() {
$("#HUEStatus").text("Unable to Retreive Bridge Configuration");
});
}, function UnableToDiscoverLocalBridgesViaPortal() {
$("#HUEStatus").text("Unable to find Local Bridge via Portal");
});
}

function StatusHeartbeat() {
MyHue.BridgeGet().then(function UpdateUI() {
$("#brightnessslider").val(MyHue.Lights[1].state.bri); // Get 1st light brightness for now...
$("#brightnessslider").slider('refresh');
setTimeout(StatusHeartbeat, 2500);
}, function BridgetHeartbeatGetFailed() {
$("#HUEStatus").text("StatusHeartbeat BridgeGet Failed");
$("#HUEInfoBar").show("slow");
});
}
</script>

<div id="container">
<div class="page" id="HueButtons">
<a href="#" data-role="button" data-icon="" onclick="JavaScript:MyHue.GroupSetHSB(1, 7000, 207, 207)">Feet Up</a>
<div class="page" align="center" id="HueButtons">
<a href="#" data-role="button" data-icon="" data-mini="true" id="feetupbutton" onclick="JavaScript:MyHue.GroupSetHSB(1, 7000, 207, 207)">Feet Up</a>


<div align="center" data-type="horizontal">
<div data-type="horizontal" min-width="128";>
<input type="range" name="brightnessslider" id="brightnessslider" value="200" min="0" max="255" />
<div data-type="horizontal" min-width="128">
<input style="display:none" data-mini="false" type="range" name="brightnessslider" id="brightnessslider" min="0" max="255" value="140" />
</div>
</div>

<div align="center" data-role="none" data-type="horizontal">
<a href="#" data-role="button" data-icon="" data-inline="true" onclick="JavaScript:MyHue.GroupSetCT(0, 467);
<a href="#" id="relaxbutton" data-role="button" data-icon="" data-inline="true" data-mini="true" onclick="JavaScript:MyHue.GroupSetCT(0, 467);
MyHue.GroupSetBrightness(0, 144)">Relax</a>
<a href="#" data-role="button" data-icon="" data-inline="true" onclick="JavaScript:MyHue.GroupSetCT(0, 156);
<a href="#" id="energizebutton" data-role="button" data-icon="" data-inline="true" data-mini="true" onclick="JavaScript:MyHue.GroupSetCT(0, 156);
MyHue.GroupSetBrightness(0, 203)">Energize</a>
<a href="#" data-role="button" data-icon="" data-inline="true" onclick="JavaScript:MyHue.GroupSetCT(0, 231);
<a href="#" id="concentratebutton" data-role="button" data-icon="" data-inline="true" data-mini="true" onclick="JavaScript:MyHue.GroupSetCT(0, 231);
MyHue.GroupSetBrightness(0, 219)">Concentrate</a>
<a href="#" data-role="button" data-icon="" data-inline="true" onclick="JavaScript:MyHue.GroupSetCT(0, 343);
<a href="#" id="readingbutton" data-role="button" data-icon="" data-inline="true" data-mini="true" onclick="JavaScript:MyHue.GroupSetCT(0, 343);
MyHue.GroupSetBrightness(0, 240)">Reading</a>
</div>

Expand All @@ -148,16 +165,16 @@

<div class="page" id="HueDirect">
<div align="center">
<canvas id="HUECanvas" width=320 height=320 >It seems your device doesn"t support the required HTML5 Canvas</canvas>
<canvas id="HUECanvas" width=320 height=320 >It seems your device doesn't support the required HTML5 Canvas</canvas>
</div>
</div><!-- /page -->

</div><!-- /container -->

<div align="center" data-role="footer" data-id="navigation" data-position="fixed">
<div data-role="controlgroup" data-type="horizontal">
<a href="#" data-role="button" data-icon="" data-inline="false" onclick="JavaScript:MyHue.GroupOff(0)">All Off</a>
<a href="#" data-role="button" data-icon="" data-inline="false" onclick="JavaScript:MyHue.GroupOn(0)">All On</a>
<a href="#" id="offbutton" data-role="button" data-icon="" data-inline="false" class="ui-btn ui-btn-b" data-mini="true" onclick="JavaScript:MyHue.GroupOff(0)">All Off</a>
<a href="#" id="onbutton" data-role="button" data-icon="" data-inline="false" class="ui-btn ui-btn-d" data-mini="true" onclick="JavaScript:MyHue.GroupOn(0)">All On</a>
</div>
<div id="HUEInfoBar">
<div id="HUEBridgeIP">
Expand All @@ -167,7 +184,7 @@
Bridge Name: . . .
</div>
<div id="HUEStatus">
Status
Status . . . .
</div>
</div>
</div><!-- /footer -->
Expand Down
Loading

0 comments on commit 47951c8

Please sign in to comment.