mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 18:58:04 +02:00
Adds port/SSL config options for RainMachine (#8986)
* Adding port/SSL config updates * New requirements generated * Made `port` and `ssl` parameters optional * Add defaults for new parameters * Re-adding guard clause * pass > continue
This commit is contained in:
committed by
Martin Hjelmare
parent
6507cc1dc8
commit
eb42d59210
@ -8,20 +8,21 @@ import voluptuous as vol
|
|||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.const import (ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS,
|
from homeassistant.const import (
|
||||||
CONF_EMAIL, CONF_IP_ADDRESS, CONF_PASSWORD,
|
ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, CONF_EMAIL, CONF_IP_ADDRESS,
|
||||||
CONF_PLATFORM, CONF_SCAN_INTERVAL)
|
CONF_PASSWORD, CONF_PLATFORM, CONF_PORT, CONF_SCAN_INTERVAL, CONF_SSL)
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = getLogger(__name__)
|
_LOGGER = getLogger(__name__)
|
||||||
REQUIREMENTS = ['regenmaschine==0.3.2']
|
REQUIREMENTS = ['regenmaschine==0.4.1']
|
||||||
|
|
||||||
ATTR_CYCLES = 'cycles'
|
ATTR_CYCLES = 'cycles'
|
||||||
ATTR_TOTAL_DURATION = 'total_duration'
|
ATTR_TOTAL_DURATION = 'total_duration'
|
||||||
|
|
||||||
CONF_HIDE_DISABLED_ENTITIES = 'hide_disabled_entities'
|
|
||||||
CONF_ZONE_RUN_TIME = 'zone_run_time'
|
CONF_ZONE_RUN_TIME = 'zone_run_time'
|
||||||
|
|
||||||
|
DEFAULT_PORT = 8080
|
||||||
|
DEFAULT_SSL = True
|
||||||
DEFAULT_ZONE_RUN_SECONDS = 60 * 10
|
DEFAULT_ZONE_RUN_SECONDS = 60 * 10
|
||||||
|
|
||||||
MIN_SCAN_TIME_LOCAL = timedelta(seconds=1)
|
MIN_SCAN_TIME_LOCAL = timedelta(seconds=1)
|
||||||
@ -42,10 +43,12 @@ PLATFORM_SCHEMA = vol.Schema(
|
|||||||
vol.Email(), # pylint: disable=no-value-for-parameter
|
vol.Email(), # pylint: disable=no-value-for-parameter
|
||||||
vol.Required(CONF_PASSWORD):
|
vol.Required(CONF_PASSWORD):
|
||||||
cv.string,
|
cv.string,
|
||||||
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT):
|
||||||
|
cv.port,
|
||||||
|
vol.Optional(CONF_SSL, default=DEFAULT_SSL):
|
||||||
|
cv.boolean,
|
||||||
vol.Optional(CONF_ZONE_RUN_TIME, default=DEFAULT_ZONE_RUN_SECONDS):
|
vol.Optional(CONF_ZONE_RUN_TIME, default=DEFAULT_ZONE_RUN_SECONDS):
|
||||||
cv.positive_int,
|
cv.positive_int
|
||||||
vol.Optional(CONF_HIDE_DISABLED_ENTITIES, default=True):
|
|
||||||
cv.boolean
|
|
||||||
}),
|
}),
|
||||||
extra=vol.ALLOW_EXTRA)
|
extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
@ -64,28 +67,34 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
_LOGGER.debug('Password: %s', password)
|
_LOGGER.debug('Password: %s', password)
|
||||||
|
|
||||||
hide_disabled_entities = config.get(CONF_HIDE_DISABLED_ENTITIES)
|
|
||||||
_LOGGER.debug('Show disabled entities: %s', hide_disabled_entities)
|
|
||||||
|
|
||||||
zone_run_time = config.get(CONF_ZONE_RUN_TIME)
|
zone_run_time = config.get(CONF_ZONE_RUN_TIME)
|
||||||
_LOGGER.debug('Zone run time: %s', zone_run_time)
|
_LOGGER.debug('Zone run time: %s', zone_run_time)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if ip_address:
|
if ip_address:
|
||||||
_LOGGER.debug('Configuring local API...')
|
port = config.get(CONF_PORT)
|
||||||
auth = rm.Authenticator.create_local(ip_address, password)
|
_LOGGER.debug('Port: %s', port)
|
||||||
|
|
||||||
|
ssl = config.get(CONF_SSL)
|
||||||
|
_LOGGER.debug('SSL: %s', ssl)
|
||||||
|
|
||||||
|
_LOGGER.debug('Configuring local API')
|
||||||
|
auth = rm.Authenticator.create_local(
|
||||||
|
ip_address, password, port=port, https=ssl)
|
||||||
elif email_address:
|
elif email_address:
|
||||||
_LOGGER.debug('Configuring remote API...')
|
_LOGGER.debug('Configuring remote API')
|
||||||
auth = rm.Authenticator.create_remote(email_address, password)
|
auth = rm.Authenticator.create_remote(email_address, password)
|
||||||
|
|
||||||
_LOGGER.debug('Instantiating RainMachine client...')
|
_LOGGER.debug('Querying against: %s', auth.url)
|
||||||
|
|
||||||
|
_LOGGER.debug('Instantiating RainMachine client')
|
||||||
client = rm.Client(auth)
|
client = rm.Client(auth)
|
||||||
|
|
||||||
rainmachine_device_name = client.provision.device_name().get('name')
|
rainmachine_device_name = client.provision.device_name().get('name')
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for program in client.programs.all().get('programs'):
|
for program in client.programs.all().get('programs'):
|
||||||
if hide_disabled_entities and program.get('active') is False:
|
if not program.get('active'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
_LOGGER.debug('Adding program: %s', program)
|
_LOGGER.debug('Adding program: %s', program)
|
||||||
@ -94,7 +103,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
client, program, device_name=rainmachine_device_name))
|
client, program, device_name=rainmachine_device_name))
|
||||||
|
|
||||||
for zone in client.zones.all().get('zones'):
|
for zone in client.zones.all().get('zones'):
|
||||||
if hide_disabled_entities and zone.get('active') is False:
|
if not zone.get('active'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
_LOGGER.debug('Adding zone: %s', zone)
|
_LOGGER.debug('Adding zone: %s', zone)
|
||||||
|
@ -829,7 +829,7 @@ radiotherm==1.3
|
|||||||
# raspihats==2.2.1
|
# raspihats==2.2.1
|
||||||
|
|
||||||
# homeassistant.components.switch.rainmachine
|
# homeassistant.components.switch.rainmachine
|
||||||
regenmaschine==0.3.2
|
regenmaschine==0.4.1
|
||||||
|
|
||||||
# homeassistant.components.python_script
|
# homeassistant.components.python_script
|
||||||
restrictedpython==4.0a3
|
restrictedpython==4.0a3
|
||||||
|
Reference in New Issue
Block a user