Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #328 from DewGew/beta
Browse files Browse the repository at this point in the history
There has been some changes in API calls from Build 15326, 1-jun-2023
  • Loading branch information
DewGew authored Aug 7, 2023
2 parents 316fa2c + 8c80e9a commit 7614a21
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 115 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/publish_beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ on:
workflow_dispatch:
branches: [ "beta" ]
jobs:
publish-docker-image:
if: github.event.pull_request.merged == true
publish-docker-image-beta:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 0 additions & 1 deletion config/default_config
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Domoticz:
roomplan: '0'
username: 'username'
password: 'password'
switchProtectionPass: '1234' #Set this to false if ask for pin function is not needed

# Report low battry
Low_battery_limit: 9
Expand Down
13 changes: 7 additions & 6 deletions const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

"""Constants for Google Assistant."""
VERSION = '1.23.7'
VERSION = '1.23.10'
PUBLIC_URL = 'https://[your public url]'
CONFIGFILE = 'config/config.yaml'
LOGFILE = 'dzga.log'
Expand All @@ -16,13 +16,14 @@
SESSION_TIMEOUT = 3600
AUTH_CODE_TIMEOUT = 600

DOMOTICZ_GET_ALL_DEVICES_URL = '/json.htm?type=devices&plan='
DOMOTICZ_GET_ONE_DEVICE_URL = '/json.htm?type=devices&rid='
DOMOTICZ_GET_SCENES_URL = '/json.htm?type=scenes'
DOMOTICZ_GET_SETTINGS_URL = '/json.htm?type=settings'
DOMOTICZ_GET_CAMERAS_URL = '/json.htm?type=cameras'
DOMOTICZ_GET_ALL_DEVICES_URL = '/json.htm?type=command&param=getdevices&plan='
DOMOTICZ_GET_ONE_DEVICE_URL = '/json.htm?type=command&param=getdevices&rid='
DOMOTICZ_GET_SCENES_URL = '/json.htm?type=command&param=getscenes'
DOMOTICZ_GET_SETTINGS_URL = '/json.htm?type=command&param=getsettings'
DOMOTICZ_GET_CAMERAS_URL = '/json.htm?type=command&param=getcameras'
DOMOTICZ_GET_VERSION = '/json.htm?type=command&param=getversion'
DOMOTICZ_SEND_COMMAND = 'json.htm?type=command&param='
DOMOTICZ_GET_PLANS = '/json.htm?type=command&param=getplans'

# https://developers.google.com/actions/smarthome/guides/
PREFIX_TYPES = 'action.devices.types.'
Expand Down
29 changes: 13 additions & 16 deletions smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
DOMOTICZ_GET_SETTINGS_URL,
DOMOTICZ_GET_ONE_DEVICE_URL,
DOMOTICZ_GET_SCENES_URL,
DOMOTICZ_GET_PLANS,
CONFIGFILE,
LOGFILE,
REQUEST_SYNC_BASE_URL,
Expand Down Expand Up @@ -251,8 +252,10 @@ def getAog(device):
aog.domain = domain
aog.id = device["idx"]
aog.entity_id = domain + aog.id
aog.plan = device.get("PlanID")
aog.state = device.get("Data", "Scene")
aog.plan = device.get("PlanID")
aog.state = device.get("Data")
if aog.domain in [DOMAINS['scene'], DOMAINS['group']]:
aog.state = device.get("Status")
aog.level = device.get("LevelInt", 0)
aog.temp = device.get("Temp")
aog.humidity = device.get("Humidity")
Expand Down Expand Up @@ -494,7 +497,7 @@ def getPlans(idx):
"""Get domoticz plan name."""
global settings

url = DOMOTICZ_URL + '/json.htm?type=plans&order=name&used=true'
url = DOMOTICZ_URL + DOMOTICZ_GET_PLANS + '&order=name&used=true'
r = requests.get(url, auth=CREDITS)

if r.status_code == 200:
Expand Down Expand Up @@ -610,17 +613,11 @@ def execute(self, command, params, challenge):
if trt.can_execute(command, params):

acknowledge = self.state.ack # ack is now stored in state
protect = self.state.protected
pincode = False

if configuration['Domoticz']['switchProtectionPass']:
protect = self.state.protected
else:
protect = False

if protect or self.state.domain == DOMAINS['security']:
pincode = configuration['Domoticz']['switchProtectionPass']
if self.state.domain == DOMAINS['security']:
pincode = self.state.seccode
pincode = self.state.seccode
acknowledge = False
if challenge is None:
raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'pinNeeded',
Expand All @@ -630,10 +627,7 @@ def execute(self, command, params, challenge):
raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'userCancelled',
'Unable to execute {} for {} - challenge needed '.format(
command, self.state.entity_id))
elif True == protect and pincode != challenge.get('pin'):
raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'challengeFailedPinNeeded',
'Unable to execute {} for {} - challenge needed '.format(
command, self.state.entity_id))

elif self.state.domain == DOMAINS['security'] and pincode != hashlib.md5(
str.encode(challenge.get('pin'))).hexdigest():
raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'challengeFailedPinNeeded',
Expand All @@ -649,7 +643,7 @@ def execute(self, command, params, challenge):
'Unable to execute {} for {} - challenge needed '.format(
command, self.state.entity_id))

trt.execute(command, params)
trt.execute(command, params, challenge)
executed = True
break

Expand Down Expand Up @@ -1203,8 +1197,11 @@ def play(self, s): #command "/play?soundfile.mp3@volume
filename = scomm
mp3_filename = FILE_DIR + "/sound/" + filename
mp3 = Path(mp3_filename)
uses_ssl = ('use_ssl' in configuration and configuration['use_ssl'] is True)
if mp3.is_file():
mp3_url = "http://" + IP_Address + ":" + IP_Port + "/sound?" + filename
if uses_ssl:
mp3_url = mp3_url.replace("http", "https")
#make a query request for Get /sound
rstatus, rmessage = SmartHomeReqHandler.playmedia(mp3_url,'audio/mp3','IDLE', 20)
else:
Expand Down
1 change: 0 additions & 1 deletion templates/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ $("#saveSettings").click(function(){
'roomplan': $('#Domoticzroomplan').val(),
'username': $('#Domoticzusername').val(),
'password': $('#Domoticzpassword').val(),
'switchProtectionPass': $('#DomoticzswitchProtectionPass').val(),
},
}
document.getElementById("saveSettings").value = JSON.stringify(stext)
Expand Down
8 changes: 0 additions & 8 deletions templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ <h4 class="card-title">Domoticz Settings</h4>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="bmd-label-floating">Switch Protection Pass</label>
<input id="DomoticzswitchProtectionPass" name="DomoticzswitchProtectionPass" type="password" class="form-control" value="{{ conf.Domoticz.switchProtectionPass }}">
</div>
</div>
</div>
<div class="clearfix"></div>
</form>
</div>
Expand Down
Loading

0 comments on commit 7614a21

Please sign in to comment.