mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Use host as config var instead of resource
This commit is contained in:
parent
1bebb17e9f
commit
f2f598bd26
@ -16,29 +16,27 @@ DEFAULT_NAME = 'myStrom Switch'
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument, too-many-function-args
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Find and return myStrom switches. """
|
""" Find and return myStrom switches. """
|
||||||
resource = config.get('resource')
|
host = config.get('host')
|
||||||
|
|
||||||
if resource is None:
|
if host is None:
|
||||||
_LOGGER.error('Missing required variable: resource')
|
_LOGGER.error('Missing required variable: host')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
resource = 'http://{}'.format(host)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
requests.get(resource, timeout=10)
|
requests.get(resource, timeout=10)
|
||||||
except requests.exceptions.MissingSchema:
|
|
||||||
_LOGGER.error("Missing resource or schema in configuration. "
|
|
||||||
"Add http:// to your URL.")
|
|
||||||
return False
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
_LOGGER.error("No route to device. "
|
_LOGGER.error("No route to device %s. "
|
||||||
"Please check the IP address in the configuration file.")
|
"Please check the IP address in the configuration file",
|
||||||
|
host)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
add_devices([MyStromSwitch(
|
add_devices([MyStromSwitch(
|
||||||
config.get('name', DEFAULT_NAME),
|
config.get('name', DEFAULT_NAME),
|
||||||
config.get('resource'))])
|
resource)])
|
||||||
|
|
||||||
|
|
||||||
class MyStromSwitch(SwitchDevice):
|
class MyStromSwitch(SwitchDevice):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user