Skip to content

Commit

Permalink
Merge pull request #12 from cwendel16834/enable_check_mode
Browse files Browse the repository at this point in the history
Enable --check mode
  • Loading branch information
tobias-richter authored Jan 9, 2021
2 parents 9d31c90 + 1c32601 commit 9ebd2b8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions action_plugins/tasmota.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def run(self, tmp=None, task_vars=None):

display.v("args: %s" % (self._task.args))

check_mode = task_vars['ansible_check_mode']
display.v("check_mode: %s" % (check_mode))

try:
# Get the tasmota host
tasmota_host = self._get_arg_or_var('tasmota_host', task_vars['ansible_host'])
Expand Down Expand Up @@ -185,11 +188,13 @@ def our_entry(x):
display.v("[%s] existing_uri: %s" % (tasmota_host, endpoint_uri))
if existing_value != incoming_value:
changed = True
change_params = copy.deepcopy(auth_params)
change_params.update( { 'cmnd' : ("%s %s" % (command, incoming_value)) } )
change_response = requests.get(url = endpoint_uri, params = change_params)
if status_response.status_code != 200:
raise AnsibleRuntimeError("Unexpected response code: %s" % (status_response.status_code))

if not check_mode:
change_params = copy.deepcopy(auth_params)
change_params.update( { 'cmnd' : ("%s %s" % (command, incoming_value)) } )
change_response = requests.get(url = endpoint_uri, params = change_params)
if status_response.status_code != 200:
raise AnsibleRuntimeError("Unexpected response code: %s" % (status_response.status_code))

if warnings:
display.warning(warnings)
Expand Down

0 comments on commit 9ebd2b8

Please sign in to comment.