#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'
|
||||||
|
while nbRetry < 3:
|
||||||
|
try:
|
||||||
request = requests.get(
|
request = requests.get(
|
||||||
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
'http://{}/relay'.format(self.ip), params={'state': value}, timeout=1)
|
||||||
if not request.status_code == 200:
|
if request.status_code == 200:
|
||||||
self._logger.info("Could not set new Relais State, Http Status Code: {}".format(request.status_code))
|
return
|
||||||
|
else:
|
||||||
|
self._logger.info(
|
||||||
|
"Could not set new Relais State, Http Status Code: {}".format(request.status_code))
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self._logger.info("Error during set Relais state")
|
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'
|
||||||
|
while nbRetry < 3:
|
||||||
|
try:
|
||||||
request = requests.post(
|
request = requests.post(
|
||||||
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
'http://{}/timer'.format(self.ip), params={'mode': value, 'time': time}, timeout=1)
|
||||||
if not request.status_code == 200:
|
if request.status_code == 200:
|
||||||
|
return
|
||||||
|
else:
|
||||||
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self._logger.info("Error during powerCycle Relais")
|
self._logger.info("Error during powerCycle Relais")
|
||||||
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def _toggleRelay(self):
|
def _toggleRelay(self):
|
||||||
|
nbRetry = 0
|
||||||
|
while nbRetry < 3:
|
||||||
try:
|
try:
|
||||||
request = requests.get(
|
request = requests.get(
|
||||||
'http://{}/toggle'.format(self.ip), timeout=1)
|
'http://{}/toggle'.format(self.ip), timeout=1)
|
||||||
if not request.status_code == 200:
|
if request.status_code == 200:
|
||||||
|
return
|
||||||
|
else:
|
||||||
self._logger.info("Could not toggle Relay State, Http Status Code: {}".format(request.status_code))
|
self._logger.info("Could not toggle Relay State, Http Status Code: {}".format(request.status_code))
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self._logger.info("Error during toggle Relais state")
|
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