mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add link to docs, fix typo, and update log output
This commit is contained in:
parent
0d05930765
commit
fb8edca942
@ -1,37 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
homeassistant.components.switch.rest
|
homeassistant.components.switch.rest
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
Allows to configure a REST switch.
|
Allows to configure a REST switch.
|
||||||
|
|
||||||
Configuration:
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/switch.rest.html
|
||||||
switch:
|
|
||||||
platform: rest
|
|
||||||
name: "Bedroom Switch"
|
|
||||||
resource: "http://IP_ADDRESS/ENDPOINT"
|
|
||||||
body_on: "ON"
|
|
||||||
body_off: "OFF"
|
|
||||||
|
|
||||||
Variables:
|
|
||||||
|
|
||||||
resource
|
|
||||||
*Required*
|
|
||||||
|
|
||||||
name
|
|
||||||
*Optional
|
|
||||||
The name of the switch. Default is 'REST Switch'.
|
|
||||||
|
|
||||||
body_on
|
|
||||||
*Optional
|
|
||||||
The body that represents enabled state. Default is "ON".
|
|
||||||
|
|
||||||
body_off
|
|
||||||
*Optional
|
|
||||||
The body that represents disabled state. Default is "OFF".
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -46,7 +20,7 @@ DEFAULT_BODY_OFF = "OFF"
|
|||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Add REST Switch """
|
""" Get REST switch. """
|
||||||
|
|
||||||
resource = config.get('resource')
|
resource = config.get('resource')
|
||||||
|
|
||||||
@ -61,7 +35,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
"Add http:// to your URL.")
|
"Add http:// to your URL.")
|
||||||
return False
|
return False
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error("No route to device. "
|
_LOGGER.error("No route to resource/endpoint. "
|
||||||
"Please check the IP address in the configuration file.")
|
"Please check the IP address in the configuration file.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -75,7 +49,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
class RestSwitch(SwitchDevice):
|
class RestSwitch(SwitchDevice):
|
||||||
""" Represents a switch that can be togggled using REST """
|
""" Represents a switch that can be toggled using REST. """
|
||||||
def __init__(self, hass, name, resource, body_on, body_off):
|
def __init__(self, hass, name, resource, body_on, body_off):
|
||||||
self._state = None
|
self._state = None
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
@ -102,7 +76,7 @@ class RestSwitch(SwitchDevice):
|
|||||||
if request.status_code == 200:
|
if request.status_code == 200:
|
||||||
self._state = True
|
self._state = True
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Can't turn on %s. Is device offline?",
|
_LOGGER.error("Can't turn on %s. Is resource/endpoint offline?",
|
||||||
self._resource)
|
self._resource)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
@ -113,7 +87,7 @@ class RestSwitch(SwitchDevice):
|
|||||||
if request.status_code == 200:
|
if request.status_code == 200:
|
||||||
self._state = False
|
self._state = False
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Can't turn off %s. Is device offline?",
|
_LOGGER.error("Can't turn off %s. Is resource/endpoint offline?",
|
||||||
self._resource)
|
self._resource)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user