Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No trait selected, passthru, thermostatMode #225

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions devices/baseDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1803,15 +1803,15 @@ class BaseDevice {
}
if (me.trait.temperaturesetting) {
const thermostat_mode = me.states.thermostatMode;
const st = " T: " + (me.states.thermostatTemperatureAmbient || '?') + " °C | S: " + (me.states.thermostatTemperatureSetpoint || '?') + "\xB0C";
const st = " T: " + (me.states.thermostatTemperatureAmbient || '?') + "°C | S: " + (me.states.thermostatTemperatureSetpoint || '?') + "\xB0C";
if (thermostat_mode === "off") {
text = "OFF " + st;
} else if (thermostat_mode === "heat" || thermostat_mode === "cool") {
fill = "green";
text = thermostat_mode.substr(0, 1).toUpperCase() + st;
} else if (thermostat_mode === "heatcool") {
fill = "green";
text = "H/C T: " + (me.states.thermostatTemperatureAmbient || '?') + " °C | S: [" + (me.states.thermostatTemperatureSetpointLow || '') + " - " + (me.states.thermostatTemperatureSetpointHigh || '')+ "] \xB0C";
text = "H/C T: " + (me.states.thermostatTemperatureAmbient || '?') + "°C | S: [" + (me.states.thermostatTemperatureSetpointLow || '') + " - " + (me.states.thermostatTemperatureSetpointHigh || '')+ "]\xB0C";
} else {
fill = "green";
text = thermostat_mode.substr(0, 1).toUpperCase() + st;
Expand Down Expand Up @@ -2300,10 +2300,10 @@ class BaseDevice {
me.clientConn.setState(me, me.states, true); // tell Google ...

me.clientConn.app.ScheduleGetState();
if (me.passthru) {
msg.payload = new_payload;
me.send(msg);
}
// if (me.passthru) {
// msg.payload = new_payload;
// me.send(msg);
// }
}
} else if (upper_topic === 'SETCHALLENGEPIN') {
const pin = String(msg.payload.pin || '');
Expand Down Expand Up @@ -2463,9 +2463,9 @@ class BaseDevice {
const differs = me.updateState(msg.payload);

if (differs) {
if (!me.passthru) {
me.send({ topic: me.topicOut, payload: me.states });
}
// if (!me.passthru) {
// me.send({ topic: me.topicOut, payload: me.states });
// }
me.clientConn.setState(me, me.states, true); // tell Google ...
me.clientConn.app.ScheduleGetState();
me.updateStatusIcon();
Expand Down Expand Up @@ -2647,15 +2647,45 @@ class BaseDevice {

updateState(new_states) {
const me = this;
let modified = false;
let modified = [];
Object.keys(me.state_types).forEach(function (key) {
if (new_states.hasOwnProperty(key)) {
if (me.setState(key, new_states[key], me.states, me.state_types[key], me.exclusive_states[key] || {})) {
me._debug('.updateState: set "' + key + '" to ' + JSON.stringify(new_states[key]));
modified = true;
modified.push(key);
}
}
});
if (modified.includes("thermostatTemperatureSetpoint")) {
me.thermostat_temperature_setpoint = me.states.thermostatTemperatureSetpoint;
}
if (modified.includes("thermostatTemperatureSetpointLow")) {
me.thermostat_temperature_setpoint_low = me.states.thermostatTemperatureSetpointLow;
}
if (modified.includes("thermostatTemperatureSetpointHigh")) {
me.thermostat_temperature_setpoint_hight = me.states.thermostatTemperatureSetpointHigh;
}
if (modified.includes("thermostatMode")) {
let keys_to_update = [];
if (me.states.thermostatMode === 'heatcool') {
keys_to_update = ['thermostatTemperatureSetpointLow', 'thermostatTemperatureSetpointHigh'];
new_states = {
thermostatTemperatureSetpointLow: me.thermostat_temperature_setpoint_low,
thermostatTemperatureSetpointHigh: me.thermostat_temperature_setpoint_hight
};
} else {
keys_to_update = ['thermostatTemperatureSetpoint'];
new_states = {
thermostatTemperatureSetpoint: me.thermostat_temperature_setpoint
};
}
keys_to_update.forEach(key => {
if (me.setState(key, new_states[key], me.states, me.state_types[key], me.exclusive_states[key] || {})) {
me._debug('.updateState: set "' + key + '" to ' + JSON.stringify(new_states[key]));
modified.push(key);
}
});
}
me._debug('.updateState: new State ' + modified + ' ' + JSON.stringify(me.states));
return modified;
}
Expand Down
34 changes: 25 additions & 9 deletions devices/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,13 @@
</div>
</div>

<!-- No Trait -->
<div class="form-row red-ui-editableList-border" id="no_trait" style="background: #fbfbfb; padding: 5px;">
<div class="form-row">
<b><label style="width:auto"><i class="fa fa-exclamation-triangle"></i> <span data-i18n="device.errors.no-trait-selected"></span></label></b>
</div>
</div>

</script>

<script type="text/javascript">
Expand Down Expand Up @@ -2900,17 +2907,17 @@
});
$("#node-input-supports_fan_speed_percent").change();

var setTraitRecomended = function (name, recommended, show_Trait) {
var setTraitRecomended = function (name, recommended, show_traits) {
$("#node-input-trait_" + name).show();
$("#label_trait_" + name).hide();
$("#cb_trait_" + name).show();
/*if (typeof recommended === "boolean") {
$("#node-input-trait_" + name).prop('checked', recommended);
}*/
let show_trait = show_Trait == "all";
if (show_Trait === "selected") {
let show_trait = show_traits == "all";
if (show_traits === "selected") {
show_trait = $("#node-input-trait_" + name).prop('checked');
} else if (show_Trait === "recommended") {
} else if (show_traits === "recommended") {
show_trait = recommended;
}
if (show_trait) {
Expand All @@ -2925,6 +2932,7 @@
$("#trait_" + name).hide();
$("#" + name).find(".oc_trait").removeClass('fa-caret-down').addClass('fa-caret-right');
}
return show_trait;
};

var setTraitRequired = function (name) {
Expand Down Expand Up @@ -3260,22 +3268,30 @@
required_traits = ["onoff"];
break;
}
let trait_shown = false;
$(".div_trait").each(function () {
let div_id = $(this).attr('id');
if (required_traits.includes(div_id)) {
setTraitRequired(div_id);
trait_shown = true;
} else {
setTraitRecomended(div_id,
device_type === 'SCENE' ? false : recommended_traits.includes(div_id),
device_type === 'SCENE' ? 'none' : (div_id === 'scene' ? false : show_trait));
//setTraitRecomended(div_id);
if (setTraitRecomended(div_id,
recommended_traits.includes(div_id),
device_type === 'SCENE' ? 'none' : (div_id === 'scene' ? false : show_trait))) {
trait_shown = true;
}
}
});
if (trait_shown) {
$("#no_trait").hide();
} else {
$("#no_trait").show();
}
};
deviceTypeChanged();
$("#node-input-device_type").change(deviceTypeChanged);
$("#node-input-show_trait").change(deviceTypeChanged);
var challenge_type_change = function() {
var challenge_type_change = function () {
let _this = $(this);
let show = _this.val() === 'pinNeeded';
if (show) {
Expand Down
3 changes: 2 additions & 1 deletion devices/locales/en-US/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@
},
"errors": {
"missing-config": "Missing SmartHome configuration",
"missing-bridge": "Missing SmartHome"
"missing-bridge": "Missing SmartHome",
"no-trait-selected": "No trait selected"
}
}
}
3 changes: 2 additions & 1 deletion devices/locales/it-IT/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@
},
"errors": {
"missing-config": "La configurazione di SmartHome non è disponibile",
"missing-bridge": "SmartHome non disponibile"
"missing-bridge": "SmartHome non disponibile",
"no-trait-selected": "Nessun tratto selezionato"
},
"trait": {
"appselector": "Applicazioni",
Expand Down