-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const Homey = require('homey'); | ||
const Device = require('../../lib/Device.js'); | ||
const boolean = require('boolean'); | ||
|
||
const refreshTimeout = 1000 * 30; // 30 sec | ||
|
||
module.exports = class ztatzP1HeatingDevice extends Device { | ||
|
||
// this method is called when the Device is inited | ||
async _initDevice() { | ||
this.log('_initDevice'); | ||
const device = this.getData(); | ||
|
||
this.setUnavailable('Please remove this device and add the new device types.'); | ||
|
||
// Register flowcard triggers | ||
//this._registerFlowCardTriggers(); | ||
|
||
// Update server data | ||
//this._syncDevice(); | ||
|
||
// Set update timer | ||
this.intervalId = setInterval(this._syncDevice.bind(this), refreshTimeout); | ||
this.setSettings({ | ||
url: device.url, | ||
}); | ||
|
||
console.log("register flow triggers"); | ||
// register Flow triggers | ||
this._flowTriggerHeatingInChanged = new Homey.FlowCardTriggerDevice('measure_temperature.in.changed').register(); | ||
this._flowTriggerHeatingOutChanged = new Homey.FlowCardTriggerDevice('measure_temperature.out.changed').register(); | ||
} | ||
|
||
async _deleteDevice() { | ||
this.log('_deleteDevice'); | ||
|
||
clearInterval(this.intervalId); | ||
} | ||
|
||
// Update server data | ||
async _syncDevice() { | ||
try { | ||
let status = await this.api.getHeating(); | ||
|
||
if (status.length != 0) { | ||
this.setAvailable(); | ||
|
||
let heatingIn = status[0][3] | ||
let heatingOut = status[0][7] | ||
|
||
this.changeCapabilityValue('measure_temperature.in', Number(heatingIn), this._flowTriggerHeatingInChanged, {'measure_temperature.in.temperature': Number(heatingIn)}); | ||
this.changeCapabilityValue('measure_temperature.out', Number(heatingOut), this._flowTriggerHeatingOutChanged, {'measure_temperature.out.temperature': Number(heatingOut)}); | ||
|
||
} else { | ||
this.setUnavailable('Cannot refresh / Connect'); | ||
} | ||
|
||
|
||
} catch (error) { | ||
this.error(error); | ||
this.setUnavailable(error.message); | ||
} | ||
} | ||
|
||
// this method is called when the Device has requested a state change (turned on or off) | ||
//async p1_kwh_used( value, opts ) { | ||
|
||
// ... set value to real device, e.g. | ||
// await setMyDeviceState({ on: value }); | ||
|
||
// or, throw an error | ||
// throw new Error('Switching the device failed!'); | ||
//} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const Homey = require('homey'); | ||
const Api = require('../../lib/Api'); | ||
const Driver = require('../../lib/Driver'); | ||
|
||
let foundDevices = []; | ||
|
||
module.exports = class ztatzP1HeatingDriver extends Driver { | ||
|
||
// This method is called when a user is adding a device | ||
// and the 'list_devices' view is called | ||
|
||
async _onPairSearchDevices(data, callback) { | ||
this.log('_onPairSearchDevices'); | ||
|
||
foundDevices = [] | ||
|
||
const api = new Api(data); | ||
|
||
await api.testConnection() | ||
.then(result => { | ||
if (result) { | ||
|
||
foundDevices = [{ | ||
name: "P1 Heating (" + data.url + ")", | ||
data: data | ||
}]; | ||
} else { | ||
this.log('No Result'); | ||
console.error('processData', data); | ||
throw new Error(Homey.__('error.permission_denied')); | ||
} | ||
}).catch(error => { | ||
callback(error); | ||
}); | ||
|
||
callback(null, true); | ||
} | ||
|
||
async _onPairListDevices(data, callback) { | ||
this.log('_onPairListDevices'); | ||
this.log(foundDevices); | ||
|
||
callback(null, foundDevices); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<style type="text/css"> | ||
#pair-template { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center | ||
} | ||
|
||
#pair-form { | ||
position: relative; | ||
width: 90% | ||
} | ||
|
||
.row { | ||
margin-bottom: 1em | ||
} | ||
|
||
.logo { | ||
display: block; | ||
position: relative; | ||
width: 25vw; | ||
height: 25vw; | ||
margin: 10vw auto; | ||
background-position: center center; | ||
background-repeat: no-repeat; | ||
background-size: contain; | ||
background-image: url(./../assets/icon.svg) | ||
} | ||
|
||
.invalid>label { | ||
color: #FF0000 !important | ||
} | ||
|
||
.invalid>input { | ||
border-bottom: 1px solid #FF0000 !important | ||
} | ||
|
||
.button { | ||
width: 100% !important | ||
} | ||
|
||
.button:disabled, | ||
.button[disabled] { | ||
background-color: #ffffff !important; | ||
color: #ffffff !important; | ||
} | ||
</style> | ||
|
||
<div id="pair-template"> | ||
<div id="pair-form"> | ||
<div class="logo"></div> | ||
|
||
<div class="row"> | ||
<label for="pair-url">URL to P1 Mon</label> | ||
<input id="pair-url" placeholder="https://p1mon.url" type="text" value="" /> | ||
</div> | ||
|
||
<div class="row"> | ||
<button class="button" id="pair-button" onclick="search();" data-i18n="login">Check</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
function search() { | ||
var error = false; | ||
let invalids = document.getElementsByClassName('invalid'); | ||
for (var i = 0; i < invalids.length; i++) { | ||
invalids[i].classList.remove('invalid'); | ||
} | ||
var pBtn = document.getElementById('pair-button'); | ||
var pUrl = document.getElementById('pair-url'); | ||
|
||
pBtn.disabled = true; | ||
if (pUrl.value.trim().length === 0) { | ||
pUrl.parentNode.classList.add('invalid'); | ||
error = true; | ||
} | ||
|
||
if (error) { | ||
pBtn.disabled = false; | ||
return false; | ||
} | ||
let data = { | ||
type: 'Heating', | ||
url: pUrl.value, | ||
}; | ||
Homey.emit('search_devices', data, (error, result) => { | ||
pBtn.disabled = false; | ||
if (error) { | ||
Homey.alert(error.message); | ||
} else { | ||
Homey.showView('list_devices'); | ||
} | ||
}); | ||
} | ||
</script> |
Oops, something went wrong.