[binary_sensor.arest] Fix name for sensor and shorten logger messages (#5460)
* Fix name for sensor and shorten logger messages * Use variable as name if none is given
This commit is contained in:
1 parent
f5062b06a9
commit
b2ecaa189a
3 files changed
+36
-51
No files matched your search
@@ -36,19 +36,17 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the aREST switches."""
|
||||
"""Set up the aREST switches."""
|
||||
resource = config.get(CONF_RESOURCE)
|
||||
|
||||
try:
|
||||
response = requests.get(resource, timeout=10)
|
||||
except requests.exceptions.MissingSchema:
|
||||
_LOGGER.error("Missing resource or schema in configuration. "
|
||||
"Add http:// to your URL.")
|
||||
"Add http:// to your URL")
|
||||
return False
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.error("No route to device at %s. "
|
||||
"Please check the IP address in the configuration file.",
|
||||
resource)
|
||||
_LOGGER.error("No route to device at %s", resource)
|
||||
return False
|
||||
|
||||
dev = []
|
||||
@@ -105,16 +103,15 @@ class ArestSwitchFunction(ArestSwitchBase):
|
||||
'{}/{}'.format(self._resource, self._func), timeout=10)
|
||||
|
||||
if request.status_code is not 200:
|
||||
_LOGGER.error("Can't find function. Is device offline?")
|
||||
_LOGGER.error("Can't find function")
|
||||
return
|
||||
|
||||
try:
|
||||
request.json()['return_value']
|
||||
except KeyError:
|
||||
_LOGGER.error("No return_value received. "
|
||||
"Is the function name correct.")
|
||||
_LOGGER.error("No return_value received")
|
||||
except ValueError:
|
||||
_LOGGER.error("Response invalid. Is the function name correct?")
|
||||
_LOGGER.error("Response invalid")
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
@@ -125,8 +122,8 @@ class ArestSwitchFunction(ArestSwitchBase):
|
||||
if request.status_code == 200:
|
||||
self._state = True
|
||||
else:
|
||||
_LOGGER.error("Can't turn on function %s at %s. "
|
||||
"Is device offline?", 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."""
|
||||
@@ -137,19 +134,18 @@ class ArestSwitchFunction(ArestSwitchBase):
|
||||
if request.status_code == 200:
|
||||
self._state = False
|
||||
else:
|
||||
_LOGGER.error("Can't turn off function %s at %s. "
|
||||
"Is device offline?", self._func, self._resource)
|
||||
_LOGGER.error(
|
||||
"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)
|
||||
request = requests.get(
|
||||
'{}/{}'.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. Is device offline?",
|
||||
self._resource)
|
||||
_LOGGER.warning("No route to device %s", self._resource)
|
||||
self._available = False
|
||||
|
||||
|
||||
@@ -164,7 +160,7 @@ class ArestSwitchPin(ArestSwitchBase):
|
||||
request = requests.get(
|
||||
'{}/mode/{}/o'.format(self._resource, self._pin), timeout=10)
|
||||
if request.status_code is not 200:
|
||||
_LOGGER.error("Can't set mode. Is device offline?")
|
||||
_LOGGER.error("Can't set mode")
|
||||
self._available = False
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
@@ -174,8 +170,8 @@ class ArestSwitchPin(ArestSwitchBase):
|
||||
if request.status_code == 200:
|
||||
self._state = True
|
||||
else:
|
||||
_LOGGER.error("Can't turn on pin %s at %s. Is device offline?",
|
||||
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."""
|
||||
@@ -184,18 +180,16 @@ class ArestSwitchPin(ArestSwitchBase):
|
||||
if request.status_code == 200:
|
||||
self._state = False
|
||||
else:
|
||||
_LOGGER.error("Can't turn off pin %s at %s. Is device offline?",
|
||||
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)
|
||||
request = requests.get(
|
||||
'{}/digital/{}'.format(self._resource, self._pin), timeout=10)
|
||||
self._state = request.json()['return_value'] != 0
|
||||
self._available = True
|
||||
except requests.exceptions.ConnectionError:
|
||||
_LOGGER.warning("No route to device %s. Is device offline?",
|
||||
self._resource)
|
||||
_LOGGER.warning("No route to device %s", self._resource)
|
||||
self._available = False
|
||||
Reference in new issue
Block a user