Fix/arest switch (#91553)
* Fix arest switch to set output when connection is lost Signed-off-by: disaster37 <linuxworkgroup@hotmail.com> * fix: lint Signed-off-by: disaster37 <linuxworkgroup@hotmail.com> --------- Signed-off-by: disaster37 <linuxworkgroup@hotmail.com>
This commit is contained in:
parent
e744632164
commit
6e8472b90f
1 changed files with 11 additions and 6 deletions
|
@ -161,16 +161,13 @@ class ArestSwitchFunction(ArestSwitchBase):
|
|||
class ArestSwitchPin(ArestSwitchBase):
|
||||
"""Representation of an aREST switch. Based on digital I/O."""
|
||||
|
||||
def __init__(self, resource, location, name, pin, invert):
|
||||
def __init__(self, resource, location, name, pin, invert) -> None:
|
||||
"""Initialize the switch."""
|
||||
super().__init__(resource, location, name)
|
||||
self._pin = pin
|
||||
self.invert = invert
|
||||
|
||||
request = requests.get(f"{resource}/mode/{pin}/o", timeout=10)
|
||||
if request.status_code != HTTPStatus.OK:
|
||||
_LOGGER.error("Can't set mode")
|
||||
self._attr_available = False
|
||||
self.__set_pin_output()
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
|
@ -200,7 +197,15 @@ class ArestSwitchPin(ArestSwitchBase):
|
|||
request = requests.get(f"{self._resource}/digital/{self._pin}", timeout=10)
|
||||
status_value = int(self.invert)
|
||||
self._attr_is_on = request.json()["return_value"] != status_value
|
||||
if self._attr_available is False:
|
||||
self._attr_available = True
|
||||
self.__set_pin_output()
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.warning("No route to device %s", self._resource)
|
||||
self._attr_available = False
|
||||
|
||||
def __set_pin_output(self) -> None:
|
||||
request = requests.get(f"{self._resource}/mode/{self._pin}/o", timeout=10)
|
||||
if request.status_code != HTTPStatus.OK:
|
||||
_LOGGER.error("Can't set mode")
|
||||
self._attr_available = False
|
||||
|
|
Loading…
Add table
Reference in a new issue