Skip to content

Commit

Permalink
running status implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Homemade-Disaster committed Jan 9, 2021
1 parent 15a7759 commit e72c2c5
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 75 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ If a API request need Parameters you can find these in the channel "parameters"
### Update requests
* setroomthermpoint ... depending of the "setting" channel it sets the temperature of each room (immediately or by using the trigger "applychanges")

### Status
* running ... here you can see if API Requests are running right now

### Request structure
<img src="https://raw.githubusercontent.com/Homemade-Disaster/ioBroker.netatmo-energy/master/docs/img/EnergyAPP_measure.png" alt="settingsLogin" width="80%"/><img src="https://raw.githubusercontent.com/Homemade-Disaster/ioBroker.netatmo-energy/master/docs/img/EnergyAPP.png" alt="settingsLogin" width="80%"/>

Expand Down
3 changes: 3 additions & 0 deletions docs/de/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Wenn ein API Request Parameter benötigt können sie diese im korrespondierenden
### Änderungs-Requests
* setroomthermpoint ... abhängig von den manuellen Änderungen im Channel "setting" werden die Änderungen an die Netatmo Energy APP übertragen. (entweder sofort oder selbst getriggert - "Temperaturänderungen sofort übertragen")

### Status
* running ... hier kann man erkenne ob derzeit ein API Request läuft

### Requeststruktur
<img src="https://raw.githubusercontent.com/Homemade-Disaster/ioBroker.netatmo-energy/master/docs/img/EnergyAPP_measure.png" alt="settingsLogin" width="80%"/><img src="https://raw.githubusercontent.com/Homemade-Disaster/ioBroker.netatmo-energy/master/docs/img/EnergyAPP.png" alt="settingsLogin" width="80%"/>

Expand Down
3 changes: 3 additions & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ If a API request need Parameters you can find these in the channel "parameters"
### Update requests
* setroomthermpoint ... depending of the "setting" channel it sets the temperature of each room (immediately or by using the trigger "applychanges")

### Status
* running ... here you can see if API Requests are running right now

### Request structure
<img src="https://raw.githubusercontent.com/Homemade-Disaster/ioBroker.netatmo-energy/master/docs/img/EnergyAPP_measure.png" alt="settingsLogin" width="80%"/><img src="https://raw.githubusercontent.com/Homemade-Disaster/ioBroker.netatmo-energy/master/docs/img/EnergyAPP.png" alt="settingsLogin" width="80%"/>

Expand Down
40 changes: 28 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ const Channel_getroommeasure = 'getroommeasure';
const Channel_getmeasure = 'getmeasure';

const Channel_setthermmode = 'setthermmode';
const Channel_status = 'status';
const Channel_trigger = 'trigger';
const Channel_switchhomeschedule = 'switchhomeschedule';
const Channel_synchomeschedule = 'synchomeschedule';
const Channel_parameters = 'parameters';

const Channel_status = 'status';
const Channel_Status_API_running = 'status';
const Channel_settings = 'settings';
const Channel_modulestatus = 'modulestatus';

Expand All @@ -77,6 +78,7 @@ const State_optimize = 'optimize';
const State_real_time = 'real_time';
const State_response = 'response';
const State_Time_Exec = 'time_exec';
const State_Status_API_running = 'running';

//Value lists
const List_mode = '{"manual": "manual temperature", "max": "maximum temperature", "hq": "frost guardian temperature", "home": "home temperature" }';
Expand Down Expand Up @@ -114,6 +116,7 @@ class NetatmoEnergy extends utils.Adapter {
this.globalDevice = null;
this.globalAPIChannel = null;
this.globalAPIChannelTrigger = null;
this.globalAPIStatus = null;
this.globalNetatmo_AccessToken = null;
this.globalRefreshToken = null;
this.globalNetatmo_ExpiresIn = 0;
Expand Down Expand Up @@ -168,6 +171,7 @@ class NetatmoEnergy extends utils.Adapter {
this.globalDevice = this.namespace + '.' + Device_APIRequests;
this.globalAPIChannel = this.namespace + '.' + Device_APIRequests + '.' + Channel_APIRequests;
this.globalAPIChannelTrigger = this.namespace + '.' + Device_APIRequests + '.' + Channel_trigger;
this.globalAPIChannelStatus = this.namespace + '.' + Device_APIRequests + '.' + Channel_Status_API_running;

this.telegram = {
type: 'message',
Expand Down Expand Up @@ -296,6 +300,8 @@ class NetatmoEnergy extends utils.Adapter {
await this.subscribeStates(this.globalAPIChannelTrigger + '.' + Trigger_applychanges);
await this.createNetatmoStructure(this.globalAPIChannelTrigger + '.' + Trigger_refresh_all, 'trigger to refresh homestructure from Netatmo Cloud', false, true, 'button', true, true, '', false, false);
await this.subscribeStates(this.globalAPIChannelTrigger + '.' + Trigger_refresh_all);
await this.createMyChannel(this.globalAPIChannelStatus, 'API Request status');
await this.createNetatmoStructure(this.globalAPIChannelStatus + '.' + State_Status_API_running, 'API running status ', false, true, 'indicator', false, true, '', false, true);
}

//Send notification after request
Expand Down Expand Up @@ -340,14 +346,17 @@ class NetatmoEnergy extends utils.Adapter {
}

// Send API inkluding tokenrequest
async sendAPIRequest(APIRequest, setpayload, norefresh) {
async sendAPIRequest(APIRequest, setpayload, norefresh, lastrequest) {
const Netatmo_Path = this.namespace;

// Refresh the token after it nearly expires
const expirationTimeInSeconds = this.globalNetatmo_ExpiresIn;
const nowInSeconds = (new Date()).getTime() / 1000;
const shouldRefresh = nowInSeconds >= expirationTimeInSeconds;

this.log.debug('Start refresh request');
await this.setState(this.globalAPIChannelStatus + '.' + State_Status_API_running, true, true);

//Send Token request to API
if (shouldRefresh || !this.globalNetatmo_AccessToken) {
this.log.info(mytools.tl('Start Token-request:', this.systemLang) + ' ' + APIRequest + ' ' + setpayload);
Expand Down Expand Up @@ -397,11 +406,18 @@ class NetatmoEnergy extends utils.Adapter {
this.log.debug(mytools.tl('API changes applied', this.systemLang) + ' ' + APIRequest);
}
this.log.debug(mytools.tl('API request finished', this.systemLang));
if (lastrequest) {
await this.setState(this.globalAPIChannelStatus + '.' + State_Status_API_running, false, true);
}
})
.catch(error => {
this.log.error(mytools.tl('API request not OK:', this.systemLang) + ' ' + error.error + ': ' + error.error_description);
this.sendRequestNotification(null, ErrorNotification, APIRequest + '\n', mytools.tl('API request not OK:', this.systemLang), error.error + ': ' + error.error_description);
});
} else {
if (lastrequest) {
await this.setState(this.globalAPIChannelStatus + '.' + State_Status_API_running, false, true);
}
}
}

Expand Down Expand Up @@ -431,13 +447,13 @@ class NetatmoEnergy extends utils.Adapter {
if ((gateway_types.match(/&/g) || []).length != 1) {
gateway_types = '&gateway_types=' + APIRequest_homesdata_NAPlug;
}
await this.sendAPIRequest(APIRequest, gateway_types, norefresh);
await this.sendAPIRequest(APIRequest, gateway_types, norefresh, true);
}

// send homesdata API Request
async sendHomestatusAPIRequest (APIRequest, norefresh) {
const device_types = await this.getValuefromDatapoint('&device_types=', this.globalAPIChannel + '.' + Channel_homestatus + '.' + Channel_parameters + '.' + State_device_types);
await this.sendAPIRequest(APIRequest, device_types, norefresh);
await this.sendAPIRequest(APIRequest, device_types, norefresh, true);
}

// send getroomsmeasure API Request
Expand All @@ -455,7 +471,7 @@ class NetatmoEnergy extends utils.Adapter {
measure_payload = measure_payload + await this.getValuefromDatapoint('&limit=', this.globalAPIChannel + '.' + Channel_getroommeasure + '.' + Channel_parameters + '.' + State_limit);
measure_payload = measure_payload + await this.getValuefromDatapoint('&optimize=', this.globalAPIChannel + '.' + Channel_getroommeasure + '.' + Channel_parameters + '.' + State_optimize);
measure_payload = measure_payload + await this.getValuefromDatapoint('&real_time=', this.globalAPIChannel + '.' + Channel_getroommeasure + '.' + Channel_parameters + '.' + State_real_time);
await this.sendAPIRequest(APIRequest, measure_payload, norefresh);
await this.sendAPIRequest(APIRequest, measure_payload, norefresh, true);
} else {
this.log.error(mytools.tl('API-getroosmeasure request is missing parameters', this.systemLang));
await this.sendRequestNotification(null, WarningNotification, APIRequest + '\n', mytools.tl('Request is missing parameters', this.systemLang), mytools.tl('Actual payload:', this.systemLang) + ' ' + measure_payload);
Expand All @@ -476,7 +492,7 @@ class NetatmoEnergy extends utils.Adapter {
measure_payload = measure_payload + await this.getValuefromDatapoint('&limit=', this.globalAPIChannel + '.' + Channel_getmeasure + '.' + Channel_parameters + '.' + State_limit);
measure_payload = measure_payload + await this.getValuefromDatapoint('&optimize=', this.globalAPIChannel + '.' + Channel_getmeasure + '.' + Channel_parameters + '.' + State_optimize);
measure_payload = measure_payload + await this.getValuefromDatapoint('&real_time=', this.globalAPIChannel + '.' + Channel_getmeasure + '.' + Channel_parameters + '.' + State_real_time);
await this.sendAPIRequest(APIRequest, measure_payload, norefresh);
await this.sendAPIRequest(APIRequest, measure_payload, norefresh, true);
} else {
this.log.error(mytools.tl('API-getmeasure request is missing parameters', this.systemLang));
await this.sendRequestNotification(null, WarningNotification, APIRequest + '\n', mytools.tl('Request is missing parameters', this.systemLang), mytools.tl('Actual payload:', this.systemLang) + ' ' + measure_payload);
Expand All @@ -490,7 +506,7 @@ class NetatmoEnergy extends utils.Adapter {
function(resolve,reject) {

const createAPIasync = async function(NetatmoRequest, mode, that) {
await that.sendAPIRequest(NetatmoRequest, mode, false);
await that.sendAPIRequest(NetatmoRequest, mode, false, true);
resolve(true);
};

Expand Down Expand Up @@ -565,8 +581,8 @@ class NetatmoEnergy extends utils.Adapter {

//Refresh whole structure
async RefreshWholeStructure (norefresh) {
await this.sendAPIRequest(APIRequest_homesdata, '',norefresh);
await this.sendAPIRequest(APIRequest_homestatus, '',norefresh);
await this.sendAPIRequest(APIRequest_homesdata, '', norefresh, false);
await this.sendAPIRequest(APIRequest_homestatus, '', norefresh, true);
}

//Apply request to API for temp
Expand All @@ -590,7 +606,7 @@ class NetatmoEnergy extends utils.Adapter {
}
await this.setState(actParent + '.' + Channel_settings + '.' + State_TempChanged_Endtime, '', true);
}
await this.sendAPIRequest(NetatmoRequest, extend_payload,false);
await this.sendAPIRequest(NetatmoRequest, extend_payload, false, true);
return true;
} else {
return false;
Expand All @@ -601,7 +617,7 @@ class NetatmoEnergy extends utils.Adapter {
async applySingleActualTemp(newTemp,actPath,actParent,NetatmoRequest,mode) {
await this.applyActualTemp(newTemp,actPath,actParent,NetatmoRequest,mode);
if (this.config.getchangesimmediately) {
await this.sendAPIRequest(APIRequest_homestatus, '',false);
await this.sendAPIRequest(APIRequest_homestatus, '', false, true);
}
}

Expand All @@ -614,7 +630,7 @@ class NetatmoEnergy extends utils.Adapter {

if ((syncmode.match(/&/g) || []).length == 4) {
syncmode = syncmode + await this.getValuefromDatapoint('&schedule_id=', this.globalAPIChannel + '.' + Channel_synchomeschedule + '.' + Channel_parameters + '.' + State_schedule_id);
await this.sendAPIRequest(NetatmoRequest, syncmode, norefresh);
await this.sendAPIRequest(NetatmoRequest, syncmode, norefresh, true);
} else {
this.log.error('API-synchomeschedule request is missing parameters');
await this.sendRequestNotification(null, WarningNotification, NetatmoRequest + '\n', 'Request is missing parameters', 'Actual payload: ' + syncmode);
Expand Down
32 changes: 20 additions & 12 deletions widgets/netatmo-energy.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
min[6]/number;
max[30]/number;
step[0.5]/number;
orientation/nselect,horizontal,vertical;
orientation[horizontal]/nselect,horizontal,vertical;
inverted/checkbox;
submitmethod[stop]/nselect,scroll,stop;
top_slider[30]/slider,0,1024,1;
Expand Down Expand Up @@ -72,24 +72,29 @@
size_refresh[15]/slider,0,300,1;
show_refresh[true]/checkbox;"
data-vis-attrs4="group.signals_widget;
windowopen_oid/hidden;
pic_windowopen/image;
xpos_window[215]/slider,0,1024,1;
ypos_window[120]/slider,0,768,1;
size_window[20]/slider,0,300,1;
show_windowopen[true]/checkbox;
reachable_oid/hidden;
pic_reachable/image;
xpos_reachable[160]/slider,0,1024,1;
ypos_reachable[119]/slider,0,768,1;
xpos_reachable[161]/slider,0,1024,1;
ypos_reachable[120]/slider,0,768,1;
size_reachhable[20]/slider,0,300,1;
show_reachable[true]/checkbox;
anticipating_oid/hidden;
pic_anticipating/image;
xpos_anticipating[190]/slider,0,1024,1;
ypos_anticipating[122]/slider,0,768,1;
xpos_anticipating[185]/slider,0,1024,1;
ypos_anticipating[123]/slider,0,768,1;
size_anticipating[15]/slider,0,300,1;
show_anticipating[true]/checkbox;"
show_anticipating[true]/checkbox;
windowopen_oid/hidden;
pic_windowopen/image;
xpos_window[205]/slider,0,1024,1;
ypos_window[121]/slider,0,768,1;
size_window[20]/slider,0,300,1;
show_windowopen[true]/checkbox;
running_oid/hidden;
pic_running/image;
xpos_running[230]/slider,0,1024,1;
ypos_running[122]/slider,0,768,1;
size_running[18]/slider,0,300,1;"
data-vis-set="netatmo-energy"
data-vis-type="ctrl,val"
data-vis-name="Thermostat">
Expand Down Expand Up @@ -125,6 +130,9 @@
<div class="netatmo-pic-frame" id="<%= this.data.attr('wid') %>_anti" style="left: <%== this.data.attr('xpos_anticipating') %>px; top: <%== this.data.attr('ypos_anticipating') %>px;">
<%= (el) -> vis.binds.netatmobasic.getanticipating(el, this.data.attr('wid'), this.data) %>
</div>
<div class="netatmo-pic-frame" id="<%= this.data.attr('wid') %>_running" style="left: <%== this.data.attr('xpos_running') %>px; top: <%== this.data.attr('ypos_running') %>px;">
<%= (el) -> vis.binds.netatmobasic.getrunning(el, this.data.attr('wid'), this.data) %>
</div>

<!-- Show title -->
<div class="netatmo-title" id="<%= this.data.attr('wid') %>_title" style="position: absolute; left: <%== this.data.attr('xpos_title') %>px; top: <%== this.data.attr('ypos_title') %>px;">
Expand Down
38 changes: 15 additions & 23 deletions widgets/netatmo-energy/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.netatmo-energy-class {
font-style: normal;
}

span.wrapper {
position:relative;
display:block;
Expand All @@ -11,12 +10,25 @@ span.wrapper div.netatmo-pic-frame {
display:block;
position:absolute;
}

p {
margin: 0px;
padding: 0px;
}

.netatmo-pic-action {
padding: 2px;
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.netatmo-pic-action:hover {
padding: 3px;
box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.5);
cursor: grab;
}
.netatmo-pic-action:active {
padding: 1px;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
cursor: grabbing;
}
.netatmo-title {
text-align: left;
white-space: nowrap;
Expand All @@ -26,7 +38,6 @@ p {
font-style: normal;
display: inline-block;
}

.netatmo-borderbutton {
position:absolute;
border: none;
Expand All @@ -42,35 +53,19 @@ p {
opacity: 1;
filter: alpha(opacity=50);
}

.netatmo-borderbutton-top {
height: 75%;
width: 100%;
}

.netatmo-borderbutton-top:hover {
background-color: white;
height: 75%;
width: 100%;
}

.netatmo-borderbutton-bottom {
top: 76%;
height: 25%;
width: 100%;
}

.netatmo-borderbutton-bottom:hover {
background-color: white;
top: 76%;
height: 25%;
width: 100%;
}

/* The slider */
.netatmo-slidergroup {
}

.netatmoSlider {
-webkit-appearance: none; /* Override default CSS styles */
/*appearance: none;*/
Expand All @@ -83,12 +78,10 @@ p {
-webkit-transition: .2s; /* 0.2 seconds transition on hover */
transition: opacity .2s;
}

/* Mouse-over effects */
.slider:hover {
opacity: 1; /* Fully shown on mouse-over */
}

/* The slider handle (use -webkit- (Chrome, Opera, Safari, Edge) and -moz- (Firefox) to override default look) */
.slider::-webkit-slider-thumb {
-webkit-appearance: none; /* Override default look */
Expand All @@ -99,7 +92,6 @@ p {
background: #4CAF50; /* Green background */
cursor: pointer; /* Cursor on hover */
}

.slider::-moz-range-thumb {
width: 30px; /* Set a specific slider handle width */
height: 30px;
Expand Down
Binary file added widgets/netatmo-energy/img/running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e72c2c5

Please sign in to comment.