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

Added SSL support #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions HomeAssistantApp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ App {
property url homeassistantScreenUrl: "HomeAssistantScreen.qml"
property url homeassistantSettingsUrl: "HomeAssistantSettings.qml"

property string imgButtonOff : "./drawables/button_off.png"
property string imgButtonOn : "./drawables/button_on.png"

property bool ssl : false

//devices
property variant devices: []
property variant groups: []
Expand All @@ -23,7 +28,8 @@ App {
"host": "",
"port": "",
"password": "",
"groups": ""
"groups": "",
"ssl": false
}


Expand All @@ -39,7 +45,7 @@ App {
}

function simpleSynchronous(device, command) {
var url = "http://" + settings.host + ":" + settings.port + "/api/services/homeassistant/" + command + "?api_password=" + encodeURIComponent(settings.password)
var url = (app.settings.ssl ? "https://" : "http://") + settings.host + ":" + settings.port + "/api/services/homeassistant/" + command + "?api_password=" + encodeURIComponent(settings.password)
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", url, true);
xmlhttp.send(JSON.stringify({
Expand Down Expand Up @@ -74,7 +80,7 @@ App {
function readDeviceStatus() {
// when in DimState no refresh of devices states
var xmlhttp = new XMLHttpRequest();
var url = "http://" + settings.host + ":" + settings.port + "/api/states?api_password=" + encodeURIComponent(ettings.password)
var url = (app.settings.ssl ? "https://" : "http://") + settings.host + ":" + settings.port + "/api/states?api_password=" + encodeURIComponent(ettings.password)
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
Expand Down
2 changes: 1 addition & 1 deletion HomeAssistantScreen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Screen {
screenTitle: qsTr("Home Assistant")

onShown: {
addCustomTopRightButton("Settings");
addCustomTopRightButton("Instellingen");
}

onCustomButtonClicked: {
Expand Down
63 changes: 63 additions & 0 deletions HomeAssistantSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Screen {
if (homeassistantPortLabel.inputText == "") homeassistantPortLabel.inputText = app.settings.port;
if (homeassistantPasswordLabel.inputText == "") homeassistantPasswordLabel.inputText = app.settings.password;
if (homeassistantGroupsLabel.inputText == "") homeassistantGroupsLabel.inputText = app.settings.groups;
app.ssl = app.settings.ssl;
sslButton.source: app.ssl ? app.imgButtonOn : app.imgButtonOff;
}

onCustomButtonClicked: {
Expand Down Expand Up @@ -141,6 +143,67 @@ Screen {
}
}

EditTextLabel {
id: homeassistantPortLabel
width: 350
height: 35
leftText: "Port"
leftTextAvailableWidth: 200

anchors {
left: homeassistantHostLabel.left
top: homeassistantHostLabel.bottom
topMargin: 10
}

onClicked: {
qnumKeyboard.open("Poort", homeassistantPortLabel.inputText, "Nummer", 1, updateHomeAssistantPortLabel, numValidate);
}
}

Rectangle {
id: sslRect
width: 200
height: 35
color: "transparent"
anchors {
top: homeassistantPortLabel.bottom
left: homeassistantPortLabel.right
}

Text {
id: sslLabel
width: 150
text: "SSL"
font.pixelSize: 12
color: "Black"
wrapMode: Text.WordWrap
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: 20
}
}

Image {
id: sslButton
width: 50
height: 35
source: app.ssl ? app.imgButtonOn : app.imgButtonOff
smooth: true
anchors {
right: parent.right
verticalCenter: parent.verticalCenter
}

MouseArea {
anchors.fill: parent
onClicked: {
app.ssl = !app.ssl
}
}
}
}

EditTextLabel {
id: homeassistantPasswordLabel
Expand Down
Binary file added drawables/button_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drawables/button_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.