mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Use constants (#3284)
This commit is contained in:
parent
cce3e284d7
commit
d48ed41122
@ -9,18 +9,15 @@ from datetime import timedelta
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (BinarySensorDevice,
|
from homeassistant.components.binary_sensor import (
|
||||||
SENSOR_CLASSES)
|
BinarySensorDevice, SENSOR_CLASSES)
|
||||||
|
from homeassistant.const import CONF_RESOURCE, CONF_PIN
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||||
|
|
||||||
CONF_RESOURCE = 'resource'
|
|
||||||
CONF_PIN = 'pin'
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the aREST binary sensor."""
|
"""Setup the aREST binary sensor."""
|
||||||
|
@ -10,7 +10,8 @@ from datetime import timedelta
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, DEVICE_DEFAULT_NAME)
|
ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, DEVICE_DEFAULT_NAME,
|
||||||
|
CONF_RESOURCE, CONF_MONITORED_VARIABLES)
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers import template
|
from homeassistant.helpers import template
|
||||||
@ -18,12 +19,8 @@ from homeassistant.util import Throttle
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago.
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||||
|
|
||||||
CONF_RESOURCE = 'resource'
|
|
||||||
CONF_MONITORED_VARIABLES = 'monitored_variables'
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the aREST sensor."""
|
"""Setup the aREST sensor."""
|
||||||
|
@ -10,14 +10,15 @@ import logging
|
|||||||
import requests
|
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, CONF_NAME, CONF_RESOURCE)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the aREST switches."""
|
"""Setup the aREST switches."""
|
||||||
resource = config.get('resource', None)
|
resource = config.get(CONF_RESOURCE, None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(resource, timeout=10)
|
response = requests.get(resource, timeout=10)
|
||||||
@ -34,18 +35,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
dev = []
|
dev = []
|
||||||
pins = config.get('pins', {})
|
pins = config.get('pins', {})
|
||||||
for pinnum, pin in pins.items():
|
for pinnum, pin in pins.items():
|
||||||
dev.append(ArestSwitchPin(resource,
|
dev.append(ArestSwitchPin(
|
||||||
config.get('name', response.json()['name']),
|
resource, config.get(CONF_NAME, response.json()['name']),
|
||||||
pin.get('name'),
|
pin.get('name'), pinnum))
|
||||||
pinnum))
|
|
||||||
|
|
||||||
functions = config.get('functions', {})
|
functions = config.get('functions', {})
|
||||||
for funcname, func in functions.items():
|
for funcname, func in functions.items():
|
||||||
dev.append(ArestSwitchFunction(resource,
|
dev.append(ArestSwitchFunction(
|
||||||
config.get('name',
|
resource, config.get(CONF_NAME, response.json()['name']),
|
||||||
response.json()['name']),
|
func.get('name'), funcname))
|
||||||
func.get('name'),
|
|
||||||
funcname))
|
|
||||||
|
|
||||||
add_devices(dev)
|
add_devices(dev)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user