Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -6,9 +6,11 @@ import requests
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDevice, PLATFORM_SCHEMA, DEVICE_CLASSES_SCHEMA)
|
||||
from homeassistant.const import (
|
||||
CONF_RESOURCE, CONF_PIN, CONF_NAME, CONF_DEVICE_CLASS)
|
||||
BinarySensorDevice,
|
||||
PLATFORM_SCHEMA,
|
||||
DEVICE_CLASSES_SCHEMA,
|
||||
)
|
||||
from homeassistant.const import CONF_RESOURCE, CONF_PIN, CONF_NAME, CONF_DEVICE_CLASS
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
@@ -16,12 +18,14 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_RESOURCE): cv.url,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_PIN): cv.string,
|
||||
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
||||
})
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_RESOURCE): cv.url,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_PIN): cv.string,
|
||||
vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
@@ -33,8 +37,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
try:
|
||||
response = requests.get(resource, timeout=10).json()
|
||||
except requests.exceptions.MissingSchema:
|
||||
_LOGGER.error("Missing resource or schema in configuration. "
|
||||
"Add http:// to your URL")
|
||||
_LOGGER.error(
|
||||
"Missing resource or schema in configuration. " "Add http:// to your URL"
|
||||
)
|
||||
return False
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to device at %s", resource)
|
||||
@@ -42,9 +47,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
arest = ArestData(resource, pin)
|
||||
|
||||
add_entities([ArestBinarySensor(
|
||||
arest, resource, config.get(CONF_NAME, response[CONF_NAME]),
|
||||
device_class, pin)], True)
|
||||
add_entities(
|
||||
[
|
||||
ArestBinarySensor(
|
||||
arest,
|
||||
resource,
|
||||
config.get(CONF_NAME, response[CONF_NAME]),
|
||||
device_class,
|
||||
pin,
|
||||
)
|
||||
],
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class ArestBinarySensor(BinarySensorDevice):
|
||||
@@ -60,7 +74,8 @@ class ArestBinarySensor(BinarySensorDevice):
|
||||
|
||||
if self._pin is not None:
|
||||
request = requests.get(
|
||||
'{}/mode/{}/i'.format(self._resource, self._pin), timeout=10)
|
||||
"{}/mode/{}/i".format(self._resource, self._pin), timeout=10
|
||||
)
|
||||
if request.status_code != 200:
|
||||
_LOGGER.error("Can't set mode of %s", self._resource)
|
||||
|
||||
@@ -72,7 +87,7 @@ class ArestBinarySensor(BinarySensorDevice):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the binary sensor is on."""
|
||||
return bool(self.arest.data.get('state'))
|
||||
return bool(self.arest.data.get("state"))
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
@@ -97,8 +112,9 @@ class ArestData:
|
||||
def update(self):
|
||||
"""Get the latest data from aREST device."""
|
||||
try:
|
||||
response = requests.get('{}/digital/{}'.format(
|
||||
self._resource, self._pin), timeout=10)
|
||||
self.data = {'state': response.json()['return_value']}
|
||||
response = requests.get(
|
||||
"{}/digital/{}".format(self._resource, self._pin), timeout=10
|
||||
)
|
||||
self.data = {"state": response.json()["return_value"]}
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to device '%s'", self._resource)
|
||||
@@ -7,8 +7,12 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, CONF_RESOURCE,
|
||||
CONF_MONITORED_VARIABLES, CONF_NAME)
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
CONF_VALUE_TEMPLATE,
|
||||
CONF_RESOURCE,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
)
|
||||
from homeassistant.exceptions import TemplateError
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
@@ -18,25 +22,31 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||
|
||||
CONF_FUNCTIONS = 'functions'
|
||||
CONF_PINS = 'pins'
|
||||
CONF_FUNCTIONS = "functions"
|
||||
CONF_PINS = "pins"
|
||||
|
||||
DEFAULT_NAME = 'aREST sensor'
|
||||
DEFAULT_NAME = "aREST sensor"
|
||||
|
||||
PIN_VARIABLE_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
})
|
||||
PIN_VARIABLE_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
}
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_RESOURCE): cv.url,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PINS, default={}):
|
||||
vol.Schema({cv.string: PIN_VARIABLE_SCHEMA}),
|
||||
vol.Optional(CONF_MONITORED_VARIABLES, default={}):
|
||||
vol.Schema({cv.string: PIN_VARIABLE_SCHEMA}),
|
||||
})
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_RESOURCE): cv.url,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PINS, default={}): vol.Schema(
|
||||
{cv.string: PIN_VARIABLE_SCHEMA}
|
||||
),
|
||||
vol.Optional(CONF_MONITORED_VARIABLES, default={}): vol.Schema(
|
||||
{cv.string: PIN_VARIABLE_SCHEMA}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
@@ -48,8 +58,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
try:
|
||||
response = requests.get(resource, timeout=10).json()
|
||||
except requests.exceptions.MissingSchema:
|
||||
_LOGGER.error("Missing resource or schema in configuration. "
|
||||
"Add http:// to your URL")
|
||||
_LOGGER.error(
|
||||
"Missing resource or schema in configuration. " "Add http:// to your URL"
|
||||
)
|
||||
return False
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to device at %s", resource)
|
||||
@@ -66,7 +77,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
def _render(value):
|
||||
try:
|
||||
return value_template.async_render({'value': value})
|
||||
return value_template.async_render({"value": value})
|
||||
except TemplateError:
|
||||
_LOGGER.exception("Error parsing value")
|
||||
return value
|
||||
@@ -77,25 +88,37 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
if var_conf is not None:
|
||||
for variable, var_data in var_conf.items():
|
||||
if variable not in response['variables']:
|
||||
if variable not in response["variables"]:
|
||||
_LOGGER.error("Variable: %s does not exist", variable)
|
||||
continue
|
||||
|
||||
renderer = make_renderer(var_data.get(CONF_VALUE_TEMPLATE))
|
||||
dev.append(ArestSensor(
|
||||
arest, resource, config.get(CONF_NAME, response[CONF_NAME]),
|
||||
var_data.get(CONF_NAME, variable), variable=variable,
|
||||
unit_of_measurement=var_data.get(CONF_UNIT_OF_MEASUREMENT),
|
||||
renderer=renderer))
|
||||
dev.append(
|
||||
ArestSensor(
|
||||
arest,
|
||||
resource,
|
||||
config.get(CONF_NAME, response[CONF_NAME]),
|
||||
var_data.get(CONF_NAME, variable),
|
||||
variable=variable,
|
||||
unit_of_measurement=var_data.get(CONF_UNIT_OF_MEASUREMENT),
|
||||
renderer=renderer,
|
||||
)
|
||||
)
|
||||
|
||||
if pins is not None:
|
||||
for pinnum, pin in pins.items():
|
||||
renderer = make_renderer(pin.get(CONF_VALUE_TEMPLATE))
|
||||
dev.append(ArestSensor(
|
||||
ArestData(resource, pinnum), resource,
|
||||
config.get(CONF_NAME, response[CONF_NAME]), pin.get(CONF_NAME),
|
||||
pin=pinnum, unit_of_measurement=pin.get(
|
||||
CONF_UNIT_OF_MEASUREMENT), renderer=renderer))
|
||||
dev.append(
|
||||
ArestSensor(
|
||||
ArestData(resource, pinnum),
|
||||
resource,
|
||||
config.get(CONF_NAME, response[CONF_NAME]),
|
||||
pin.get(CONF_NAME),
|
||||
pin=pinnum,
|
||||
unit_of_measurement=pin.get(CONF_UNIT_OF_MEASUREMENT),
|
||||
renderer=renderer,
|
||||
)
|
||||
)
|
||||
|
||||
add_entities(dev, True)
|
||||
|
||||
@@ -103,12 +126,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class ArestSensor(Entity):
|
||||
"""Implementation of an aREST sensor for exposed variables."""
|
||||
|
||||
def __init__(self, arest, resource, location, name, variable=None,
|
||||
pin=None, unit_of_measurement=None, renderer=None):
|
||||
def __init__(
|
||||
self,
|
||||
arest,
|
||||
resource,
|
||||
location,
|
||||
name,
|
||||
variable=None,
|
||||
pin=None,
|
||||
unit_of_measurement=None,
|
||||
renderer=None,
|
||||
):
|
||||
"""Initialize the sensor."""
|
||||
self.arest = arest
|
||||
self._resource = resource
|
||||
self._name = '{} {}'.format(location.title(), name.title())
|
||||
self._name = "{} {}".format(location.title(), name.title())
|
||||
self._variable = variable
|
||||
self._pin = pin
|
||||
self._state = None
|
||||
@@ -117,7 +149,8 @@ class ArestSensor(Entity):
|
||||
|
||||
if self._pin is not None:
|
||||
request = requests.get(
|
||||
'{}/mode/{}/i'.format(self._resource, self._pin), timeout=10)
|
||||
"{}/mode/{}/i".format(self._resource, self._pin), timeout=10
|
||||
)
|
||||
if request.status_code != 200:
|
||||
_LOGGER.error("Can't set mode of %s", self._resource)
|
||||
|
||||
@@ -136,11 +169,10 @@ class ArestSensor(Entity):
|
||||
"""Return the state of the sensor."""
|
||||
values = self.arest.data
|
||||
|
||||
if 'error' in values:
|
||||
return values['error']
|
||||
if "error" in values:
|
||||
return values["error"]
|
||||
|
||||
value = self._renderer(
|
||||
values.get('value', values.get(self._variable, None)))
|
||||
value = self._renderer(values.get("value", values.get(self._variable, None)))
|
||||
return value
|
||||
|
||||
def update(self):
|
||||
@@ -169,17 +201,20 @@ class ArestData:
|
||||
try:
|
||||
if self._pin is None:
|
||||
response = requests.get(self._resource, timeout=10)
|
||||
self.data = response.json()['variables']
|
||||
self.data = response.json()["variables"]
|
||||
else:
|
||||
try:
|
||||
if str(self._pin[0]) == 'A':
|
||||
response = requests.get('{}/analog/{}'.format(
|
||||
self._resource, self._pin[1:]), timeout=10)
|
||||
self.data = {'value': response.json()['return_value']}
|
||||
if str(self._pin[0]) == "A":
|
||||
response = requests.get(
|
||||
"{}/analog/{}".format(self._resource, self._pin[1:]),
|
||||
timeout=10,
|
||||
)
|
||||
self.data = {"value": response.json()["return_value"]}
|
||||
except TypeError:
|
||||
response = requests.get('{}/digital/{}'.format(
|
||||
self._resource, self._pin), timeout=10)
|
||||
self.data = {'value': response.json()['return_value']}
|
||||
response = requests.get(
|
||||
"{}/digital/{}".format(self._resource, self._pin), timeout=10
|
||||
)
|
||||
self.data = {"value": response.json()["return_value"]}
|
||||
self.available = True
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to device %s", self._resource)
|
||||
|
||||
@@ -5,31 +5,37 @@ import logging
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
|
||||
from homeassistant.const import (CONF_NAME, CONF_RESOURCE)
|
||||
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_NAME, CONF_RESOURCE
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_FUNCTIONS = 'functions'
|
||||
CONF_PINS = 'pins'
|
||||
CONF_INVERT = 'invert'
|
||||
CONF_FUNCTIONS = "functions"
|
||||
CONF_PINS = "pins"
|
||||
CONF_INVERT = "invert"
|
||||
|
||||
DEFAULT_NAME = 'aREST switch'
|
||||
DEFAULT_NAME = "aREST switch"
|
||||
|
||||
PIN_FUNCTION_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_INVERT, default=False): cv.boolean,
|
||||
})
|
||||
PIN_FUNCTION_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_INVERT, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_RESOURCE): cv.url,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PINS, default={}):
|
||||
vol.Schema({cv.string: PIN_FUNCTION_SCHEMA}),
|
||||
vol.Optional(CONF_FUNCTIONS, default={}):
|
||||
vol.Schema({cv.string: PIN_FUNCTION_SCHEMA}),
|
||||
})
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_RESOURCE): cv.url,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PINS, default={}): vol.Schema(
|
||||
{cv.string: PIN_FUNCTION_SCHEMA}
|
||||
),
|
||||
vol.Optional(CONF_FUNCTIONS, default={}): vol.Schema(
|
||||
{cv.string: PIN_FUNCTION_SCHEMA}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
@@ -39,8 +45,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
try:
|
||||
response = requests.get(resource, timeout=10)
|
||||
except requests.exceptions.MissingSchema:
|
||||
_LOGGER.error("Missing resource or schema in configuration. "
|
||||
"Add http:// to your URL")
|
||||
_LOGGER.error(
|
||||
"Missing resource or schema in configuration. " "Add http:// to your URL"
|
||||
)
|
||||
return False
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to device at %s", resource)
|
||||
@@ -49,15 +56,26 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
dev = []
|
||||
pins = config.get(CONF_PINS)
|
||||
for pinnum, pin in pins.items():
|
||||
dev.append(ArestSwitchPin(
|
||||
resource, config.get(CONF_NAME, response.json()[CONF_NAME]),
|
||||
pin.get(CONF_NAME), pinnum, pin.get(CONF_INVERT)))
|
||||
dev.append(
|
||||
ArestSwitchPin(
|
||||
resource,
|
||||
config.get(CONF_NAME, response.json()[CONF_NAME]),
|
||||
pin.get(CONF_NAME),
|
||||
pinnum,
|
||||
pin.get(CONF_INVERT),
|
||||
)
|
||||
)
|
||||
|
||||
functions = config.get(CONF_FUNCTIONS)
|
||||
for funcname, func in functions.items():
|
||||
dev.append(ArestSwitchFunction(
|
||||
resource, config.get(CONF_NAME, response.json()[CONF_NAME]),
|
||||
func.get(CONF_NAME), funcname))
|
||||
dev.append(
|
||||
ArestSwitchFunction(
|
||||
resource,
|
||||
config.get(CONF_NAME, response.json()[CONF_NAME]),
|
||||
func.get(CONF_NAME),
|
||||
funcname,
|
||||
)
|
||||
)
|
||||
|
||||
add_entities(dev)
|
||||
|
||||
@@ -68,7 +86,7 @@ class ArestSwitchBase(SwitchDevice):
|
||||
def __init__(self, resource, location, name):
|
||||
"""Initialize the switch."""
|
||||
self._resource = resource
|
||||
self._name = '{} {}'.format(location.title(), name.title())
|
||||
self._name = "{} {}".format(location.title(), name.title())
|
||||
self._state = None
|
||||
self._available = True
|
||||
|
||||
@@ -96,15 +114,14 @@ class ArestSwitchFunction(ArestSwitchBase):
|
||||
super().__init__(resource, location, name)
|
||||
self._func = func
|
||||
|
||||
request = requests.get(
|
||||
'{}/{}'.format(self._resource, self._func), timeout=10)
|
||||
request = requests.get("{}/{}".format(self._resource, self._func), timeout=10)
|
||||
|
||||
if request.status_code != 200:
|
||||
_LOGGER.error("Can't find function")
|
||||
return
|
||||
|
||||
try:
|
||||
request.json()['return_value']
|
||||
request.json()["return_value"]
|
||||
except KeyError:
|
||||
_LOGGER.error("No return_value received")
|
||||
except ValueError:
|
||||
@@ -113,33 +130,38 @@ class ArestSwitchFunction(ArestSwitchBase):
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
request = requests.get(
|
||||
'{}/{}'.format(self._resource, self._func), timeout=10,
|
||||
params={'params': '1'})
|
||||
"{}/{}".format(self._resource, self._func),
|
||||
timeout=10,
|
||||
params={"params": "1"},
|
||||
)
|
||||
|
||||
if request.status_code == 200:
|
||||
self._state = True
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Can't turn on function %s at %s", self._func, self._resource)
|
||||
_LOGGER.error("Can't turn on function %s at %s", self._func, self._resource)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
request = requests.get(
|
||||
'{}/{}'.format(self._resource, self._func), timeout=10,
|
||||
params={'params': '0'})
|
||||
"{}/{}".format(self._resource, self._func),
|
||||
timeout=10,
|
||||
params={"params": "0"},
|
||||
)
|
||||
|
||||
if request.status_code == 200:
|
||||
self._state = False
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Can't turn off function %s at %s", self._func, self._resource)
|
||||
"Can't turn off function %s at %s", self._func, self._resource
|
||||
)
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from aREST API and update the state."""
|
||||
try:
|
||||
request = requests.get(
|
||||
'{}/{}'.format(self._resource, self._func), timeout=10)
|
||||
self._state = request.json()['return_value'] != 0
|
||||
"{}/{}".format(self._resource, self._func), timeout=10
|
||||
)
|
||||
self._state = request.json()["return_value"] != 0
|
||||
self._available = True
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.warning("No route to device %s", self._resource)
|
||||
@@ -156,7 +178,8 @@ class ArestSwitchPin(ArestSwitchBase):
|
||||
self.invert = invert
|
||||
|
||||
request = requests.get(
|
||||
'{}/mode/{}/o'.format(self._resource, self._pin), timeout=10)
|
||||
"{}/mode/{}/o".format(self._resource, self._pin), timeout=10
|
||||
)
|
||||
if request.status_code != 200:
|
||||
_LOGGER.error("Can't set mode")
|
||||
self._available = False
|
||||
@@ -165,35 +188,34 @@ class ArestSwitchPin(ArestSwitchBase):
|
||||
"""Turn the device on."""
|
||||
turn_on_payload = int(not self.invert)
|
||||
request = requests.get(
|
||||
'{}/digital/{}/{}'.format(self._resource, self._pin,
|
||||
turn_on_payload),
|
||||
timeout=10)
|
||||
"{}/digital/{}/{}".format(self._resource, self._pin, turn_on_payload),
|
||||
timeout=10,
|
||||
)
|
||||
if request.status_code == 200:
|
||||
self._state = True
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Can't turn on pin %s at %s", self._pin, self._resource)
|
||||
_LOGGER.error("Can't turn on pin %s at %s", self._pin, self._resource)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
turn_off_payload = int(self.invert)
|
||||
request = requests.get(
|
||||
'{}/digital/{}/{}'.format(self._resource, self._pin,
|
||||
turn_off_payload),
|
||||
timeout=10)
|
||||
"{}/digital/{}/{}".format(self._resource, self._pin, turn_off_payload),
|
||||
timeout=10,
|
||||
)
|
||||
if request.status_code == 200:
|
||||
self._state = False
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Can't turn off pin %s at %s", self._pin, self._resource)
|
||||
_LOGGER.error("Can't turn off pin %s at %s", self._pin, self._resource)
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from aREST API and update the state."""
|
||||
try:
|
||||
request = requests.get(
|
||||
'{}/digital/{}'.format(self._resource, self._pin), timeout=10)
|
||||
"{}/digital/{}".format(self._resource, self._pin), timeout=10
|
||||
)
|
||||
status_value = int(self.invert)
|
||||
self._state = request.json()['return_value'] != status_value
|
||||
self._state = request.json()["return_value"] != status_value
|
||||
self._available = True
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.warning("No route to device %s", self._resource)
|
||||
|
||||
Reference in new issue
Block a user