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

Commit

Permalink
Added already instate for onoff trait
Browse files Browse the repository at this point in the history
  • Loading branch information
DewGew authored Jan 2, 2023
1 parent f432454 commit f03ffb0
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,28 @@ def query_attributes(self):
def execute(self, command, params):
"""Execute an OnOff command."""
domain = self.state.domain
state = self.state.state
protected = self.state.protected

if domain not in [DOMAINS['sensor']]:
if domain == DOMAINS['group']:
url = DOMOTICZ_URL + '/json.htm?type=command&param=switchscene&idx=' + self.state.id + '&switchcmd=' + (
'On' if params['on'] else 'Off')
url = DOMOTICZ_URL + '/json.htm?type=command&param=switchscene&idx=' + self.state.id + '&switchcmd='
if params['on'] is True and state == 'Off':
url += 'On'
elif params['on'] is False and state == 'On':
url += 'Off'
else:
raise SmartHomeError(ERR_ALREADY_IN_STATE,
'Unable to execute {} for {}. Already in state '.format(command, self.state.entity_id))
else:
url = DOMOTICZ_URL + '/json.htm?type=command&param=switchlight&idx=' + self.state.id + '&switchcmd=' + (
'On' if params['on'] else 'Off')
url = DOMOTICZ_URL + '/json.htm?type=command&param=switchlight&idx=' + self.state.id + '&switchcmd='
if params['on'] is True and state == 'Off':
url += 'On'
elif params['on'] is False and state == 'On':
url += 'Off'
else:
raise SmartHomeError(ERR_ALREADY_IN_STATE,
'Unable to execute {} for {}. Already in state '.format(command, self.state.entity_id))

if protected:
url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass']
Expand All @@ -209,8 +222,7 @@ def execute(self, command, params):
if err == 'ERROR':
raise SmartHomeError(ERR_WRONG_PIN,
'Unable to execute {} for {} check your settings'.format(command,
self.state.entity_id))

self.state.entity_id))

@register_trait
class SceneTrait(_Trait):
Expand Down

0 comments on commit f03ffb0

Please sign in to comment.