8000 Support splitting of input_boolean config by Danielhiversen · Pull Request #3564 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Support splitting of input_boolean config #3564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions homeassistant/components/input_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
SERVICE_TOGGLE, STATE_ON)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity_component import (EntityComponent,
generate_entity_id)
from homeassistant.helpers import extract_domain_configs

DOMAIN = 'input_boolean'

Expand Down Expand Up @@ -60,16 +62,20 @@ def setup(hass, config):
component = EntityComponent(_LOGGER, DOMAIN, hass)

entities = []
entity_ids = []

for object_id, cfg in config[DOMAIN].items():
if not cfg:
cfg = {}
for config_key in extract_domain_configs(config, DOMAIN):
for object_id, cfg in config[config_key].items():
if not cfg:
cfg = {}

name = cfg.get(CONF_NAME)
state = cfg.get(CONF_INITIAL, False)
icon = cfg.get(CONF_ICON)

entities.append(InputBoolean(object_id, name, state, icon))
name = cfg.get(CONF_NAME)
state = cfg.get(CONF_INITIAL, False)
icon = cfg.get(CONF_ICON)
entity_id = generate_entity_id(ENTITY_ID_FORMAT,
object_id, entity_ids)
entity_ids.append(entity_id)
entities.append(InputBoolean(entity_id, name, state, icon))

if not entities:
return False
Expand Down Expand Up @@ -101,9 +107,9 @@ def handler_service(service):
class InputBoolean(ToggleEntity):
"""Representation of a boolean input."""

def __init__(self, object_id, name, state, icon):
def __init__(self, entity_id, name, state, icon):
"""Initialize a boolean input."""
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
self.entity_id = entity_id
self._name = name
self._state = state
self._icon = icon
Expand Down
26 changes: 24 additions & 2 deletions tests/components/test_input_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,41 @@ def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()

def test_config(self):
def test_config_invalid_config(self):
"""Test config."""
invalid_configs = [
None,
1,
{},
{'name with space': None},
]

for cfg in invalid_configs:
self.assertFalse(
setup_component(self.hass, DOMAIN, {DOMAIN: cfg}))

def test_config_valid_config(self):
"""Test config."""
self.assertTrue(setup_component(self.hass, DOMAIN, {DOMAIN: {
'test_1': None}, DOMAIN + " 2": {'test_2': {'initial': True}}}))

entity_id = 'input_boolean.test_1'
entity_id2 = 'input_boolean.test_2'

self.assertFalse(
is_on(self.hass, entity_id))
self.assertTrue(
is_on(self.hass, entity_id2))

turn_on(self.hass, entity_id)
turn_off(self.hass, entity_id2)

self.hass.block_till_done()

self.assertTrue(
is_on(self.hass, entity_id))
self.assertFalse(
is_on(self.hass, entity_id2))

def test_methods(self):
"""Test is_on, turn_on, turn_off methods."""
self.assertTrue(setup_component(self.hass, DOMAIN, {DOMAIN: {
Expand Down
0