mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Modify the import style
This commit is contained in:
parent
5dfd0d2502
commit
332ac794a4
@ -8,7 +8,7 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/switch.arest.html
|
https://home-assistant.io/components/switch.arest.html
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from requests import get, exceptions
|
import requests
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||||
@ -22,12 +22,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
resource = config.get('resource', None)
|
resource = config.get('resource', None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = get(resource, timeout=10)
|
response = requests.get(resource, timeout=10)
|
||||||
except exceptions.MissingSchema:
|
except requests.exceptions.MissingSchema:
|
||||||
_LOGGER.error("Missing resource or schema in configuration. "
|
_LOGGER.error("Missing resource or schema in configuration. "
|
||||||
"Add http:// to your URL.")
|
"Add http:// to your URL.")
|
||||||
return False
|
return False
|
||||||
except exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error("No route to device. "
|
_LOGGER.error("No route to device. "
|
||||||
"Please check the IP address in the configuration file.")
|
"Please check the IP address in the configuration file.")
|
||||||
return False
|
return False
|
||||||
@ -52,8 +52,8 @@ class ArestSwitch(SwitchDevice):
|
|||||||
self._pin = pin
|
self._pin = pin
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
request = get('{}/mode/{}/o'.format(self._resource, self._pin),
|
request = requests.get('{}/mode/{}/o'.format(self._resource,
|
||||||
timeout=10)
|
self._pin), timeout=10)
|
||||||
if request.status_code is not 200:
|
if request.status_code is not 200:
|
||||||
_LOGGER.error("Can't set mode. Is device offline?")
|
_LOGGER.error("Can't set mode. Is device offline?")
|
||||||
|
|
||||||
@ -69,8 +69,8 @@ class ArestSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the device on. """
|
""" Turn the device on. """
|
||||||
request = get('{}/digital/{}/1'.format(self._resource, self._pin),
|
request = requests.get('{}/digital/{}/1'.format(self._resource,
|
||||||
timeout=10)
|
self._pin), timeout=10)
|
||||||
if request.status_code == 200:
|
if request.status_code == 200:
|
||||||
self._state = True
|
self._state = True
|
||||||
else:
|
else:
|
||||||
@ -79,8 +79,8 @@ class ArestSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
request = get('{}/digital/{}/0'.format(self._resource, self._pin),
|
request = requests.get('{}/digital/{}/0'.format(self._resource,
|
||||||
timeout=10)
|
self._pin), timeout=10)
|
||||||
if request.status_code == 200:
|
if request.status_code == 200:
|
||||||
self._state = False
|
self._state = False
|
||||||
else:
|
else:
|
||||||
@ -89,6 +89,6 @@ class ArestSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
""" Gets the latest data from aREST API and updates the state. """
|
""" Gets the latest data from aREST API and updates the state. """
|
||||||
request = get('{}/digital/{}'.format(self._resource, self._pin),
|
request = requests.get('{}/digital/{}'.format(self._resource,
|
||||||
timeout=10)
|
self._pin), timeout=10)
|
||||||
self._state = request.json()['return_value'] != 0
|
self._state = request.json()['return_value'] != 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user