#13 Wenn Request fehlschägt max. 3x versuchen
This commit is contained in:
parent
5d002ffc88
commit
d2e1b00b3f
@ -84,40 +84,56 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.info("Ip is None")
|
self._logger.info("Ip is None")
|
||||||
|
|
||||||
def _setRelaisState(self, newState):
|
def _setRelaisState(self, newState):
|
||||||
try:
|
nbRetry = 0
|
||||||
value = '0'
|
value = '0'
|
||||||
if (newState == True):
|
if (newState == True):
|
||||||
value = '1'
|
value = '1'
|
||||||
request = requests.get(
|
while nbRetry < 3:
|
||||||
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
try:
|
||||||
if not request.status_code == 200:
|
request = requests.get(
|
||||||
self._logger.info("Could not set new Relais State, Http Status Code: {}".format(request.status_code))
|
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
||||||
except requests.exceptions.ConnectionError:
|
if request.status_code == 200:
|
||||||
self._logger.info("Error during set Relais state")
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info(
|
||||||
|
"Could not set new Relais State, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during set Relais state")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
# Sets the switch to a specific inverse newState,
|
# Sets the switch to a specific inverse newState,
|
||||||
# waits for a specified amount of time (max 3h),
|
# waits for a specified amount of time (max 3h),
|
||||||
# then sets the the switch to the newState.
|
# then sets the the switch to the newState.
|
||||||
def _powerCycleRelais(self, newState, time):
|
def _powerCycleRelais(self, newState, time):
|
||||||
try:
|
nbRetry = 0
|
||||||
value = 'on'
|
value = 'on'
|
||||||
if (newState == True):
|
if newState:
|
||||||
value = 'off'
|
value = 'off'
|
||||||
request = requests.post(
|
while nbRetry < 3:
|
||||||
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
try:
|
||||||
if not request.status_code == 200:
|
request = requests.post(
|
||||||
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
||||||
except requests.exceptions.ConnectionError:
|
if request.status_code == 200:
|
||||||
self._logger.info("Error during powerCycle Relais")
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during powerCycle Relais")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def _toggleRelay(self):
|
def _toggleRelay(self):
|
||||||
try:
|
nbRetry = 0
|
||||||
request = requests.get(
|
while nbRetry < 3:
|
||||||
'http://{}/toggle'.format(self.ip), timeout=1)
|
try:
|
||||||
if not request.status_code == 200:
|
request = requests.get(
|
||||||
self._logger.info("Could not toggle Relay State, Http Status Code: {}".format(request.status_code))
|
'http://{}/toggle'.format(self.ip), timeout=1)
|
||||||
except requests.exceptions.ConnectionError:
|
if request.status_code == 200:
|
||||||
self._logger.info("Error during toggle Relais state")
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info("Could not toggle Relay State, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during toggle Relais state")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def on_api_command(self, command, data):
|
def on_api_command(self, command, data):
|
||||||
if command == "enableRelais":
|
if command == "enableRelais":
|
||||||
|
Loading…
Reference in New Issue
Block a user