Move counter component (#10332)
* Fix docstring * Add comment * Move counter to folder * Fix missing parts * Commit it when file is savedpull/10365/head
parent
5be6f8ff36
commit
a5d5f3f727
|
@ -140,13 +140,13 @@ def async_setup(hass, config):
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN, SERVICE_INCREMENT, async_handler_service,
|
DOMAIN, SERVICE_INCREMENT, async_handler_service,
|
||||||
descriptions[DOMAIN][SERVICE_INCREMENT], SERVICE_SCHEMA)
|
descriptions[SERVICE_INCREMENT], SERVICE_SCHEMA)
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN, SERVICE_DECREMENT, async_handler_service,
|
DOMAIN, SERVICE_DECREMENT, async_handler_service,
|
||||||
descriptions[DOMAIN][SERVICE_DECREMENT], SERVICE_SCHEMA)
|
descriptions[SERVICE_DECREMENT], SERVICE_SCHEMA)
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN, SERVICE_RESET, async_handler_service,
|
DOMAIN, SERVICE_RESET, async_handler_service,
|
||||||
descriptions[DOMAIN][SERVICE_RESET], SERVICE_SCHEMA)
|
descriptions[SERVICE_RESET], SERVICE_SCHEMA)
|
||||||
|
|
||||||
yield from component.async_add_entities(entities)
|
yield from component.async_add_entities(entities)
|
||||||
return True
|
return True
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Describes the format for available counter services
|
||||||
|
|
||||||
|
decrement:
|
||||||
|
description: Decrement a counter.
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Entity id of the counter to decrement.
|
||||||
|
example: 'counter.count0'
|
||||||
|
increment:
|
||||||
|
description: Increment a counter.
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Entity id of the counter to increment.
|
||||||
|
example: 'counter.count0'
|
||||||
|
reset:
|
||||||
|
description: Reset a counter.
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Entity id of the counter to reset.
|
||||||
|
example: 'counter.count0'
|
|
@ -390,26 +390,6 @@ rflink:
|
||||||
description: The command to be sent.
|
description: The command to be sent.
|
||||||
example: 'on'
|
example: 'on'
|
||||||
|
|
||||||
counter:
|
|
||||||
decrement:
|
|
||||||
description: Decrement a counter.
|
|
||||||
fields:
|
|
||||||
entity_id:
|
|
||||||
description: Entity id of the counter to decrement.
|
|
||||||
example: 'counter.count0'
|
|
||||||
increment:
|
|
||||||
description: Increment a counter.
|
|
||||||
fields:
|
|
||||||
entity_id:
|
|
||||||
description: Entity id of the counter to increment.
|
|
||||||
example: 'counter.count0'
|
|
||||||
reset:
|
|
||||||
description: Reset a counter.
|
|
||||||
fields:
|
|
||||||
entity_id:
|
|
||||||
description: Entity id of the counter to reset.
|
|
||||||
example: 'counter.count0'
|
|
||||||
|
|
||||||
abode:
|
abode:
|
||||||
change_setting:
|
change_setting:
|
||||||
description: Change an Abode system setting.
|
description: Change an Abode system setting.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Describes the format for available timer services
|
||||||
|
|
||||||
start:
|
start:
|
||||||
description: Start a timer.
|
description: Start a timer.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
"""Tests for the counter component."""
|
|
@ -42,6 +42,47 @@ class TestCounter(unittest.TestCase):
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
setup_component(self.hass, DOMAIN, {DOMAIN: cfg}))
|
setup_component(self.hass, DOMAIN, {DOMAIN: cfg}))
|
||||||
|
|
||||||
|
def test_config_options(self):
|
||||||
|
"""Test configuration options."""
|
||||||
|
count_start = len(self.hass.states.entity_ids())
|
||||||
|
|
||||||
|
_LOGGER.debug('ENTITIES @ start: %s', self.hass.states.entity_ids())
|
||||||
|
|
||||||
|
config = {
|
||||||
|
DOMAIN: {
|
||||||
|
'test_1': {},
|
||||||
|
'test_2': {
|
||||||
|
CONF_NAME: 'Hello World',
|
||||||
|
CONF_ICON: 'mdi:work',
|
||||||
|
CONF_INITIAL: 10,
|
||||||
|
CONF_STEP: 5,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert setup_component(self.hass, 'counter', config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
|
_LOGGER.debug('ENTITIES: %s', self.hass.states.entity_ids())
|
||||||
|
|
||||||
|
self.assertEqual(count_start + 2, len(self.hass.states.entity_ids()))
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
|
state_1 = self.hass.states.get('counter.test_1')
|
||||||
|
state_2 = self.hass.states.get('counter.test_2')
|
||||||
|
|
||||||
|
self.assertIsNotNone(state_1)
|
||||||
|
self.assertIsNotNone(state_2)
|
||||||
|
|
||||||
|
self.assertEqual(0, int(state_1.state))
|
||||||
|
self.assertNotIn(ATTR_ICON, state_1.attributes)
|
||||||
|
self.assertNotIn(ATTR_FRIENDLY_NAME, state_1.attributes)
|
||||||
|
|
||||||
|
self.assertEqual(10, int(state_2.state))
|
||||||
|
self.assertEqual('Hello World',
|
||||||
|
state_2.attributes.get(ATTR_FRIENDLY_NAME))
|
||||||
|
self.assertEqual('mdi:work', state_2.attributes.get(ATTR_ICON))
|
||||||
|
|
||||||
def test_methods(self):
|
def test_methods(self):
|
||||||
"""Test increment, decrement, and reset methods."""
|
"""Test increment, decrement, and reset methods."""
|
||||||
config = {
|
config = {
|
||||||
|
@ -118,47 +159,6 @@ class TestCounter(unittest.TestCase):
|
||||||
state = self.hass.states.get(entity_id)
|
state = self.hass.states.get(entity_id)
|
||||||
self.assertEqual(15, int(state.state))
|
self.assertEqual(15, int(state.state))
|
||||||
|
|
||||||
def test_config_options(self):
|
|
||||||
"""Test configuration options."""
|
|
||||||
count_start = len(self.hass.states.entity_ids())
|
|
||||||
|
|
||||||
_LOGGER.debug('ENTITIES @ start: %s', self.hass.states.entity_ids())
|
|
||||||
|
|
||||||
config = {
|
|
||||||
DOMAIN: {
|
|
||||||
'test_1': {},
|
|
||||||
'test_2': {
|
|
||||||
CONF_NAME: 'Hello World',
|
|
||||||
CONF_ICON: 'mdi:work',
|
|
||||||
CONF_INITIAL: 10,
|
|
||||||
CONF_STEP: 5,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert setup_component(self.hass, 'counter', config)
|
|
||||||
self.hass.block_till_done()
|
|
||||||
|
|
||||||
_LOGGER.debug('ENTITIES: %s', self.hass.states.entity_ids())
|
|
||||||
|
|
||||||
self.assertEqual(count_start + 2, len(self.hass.states.entity_ids()))
|
|
||||||
self.hass.block_till_done()
|
|
||||||
|
|
||||||
state_1 = self.hass.states.get('counter.test_1')
|
|
||||||
state_2 = self.hass.states.get('counter.test_2')
|
|
||||||
|
|
||||||
self.assertIsNotNone(state_1)
|
|
||||||
self.assertIsNotNone(state_2)
|
|
||||||
|
|
||||||
self.assertEqual(0, int(state_1.state))
|
|
||||||
self.assertNotIn(ATTR_ICON, state_1.attributes)
|
|
||||||
self.assertNotIn(ATTR_FRIENDLY_NAME, state_1.attributes)
|
|
||||||
|
|
||||||
self.assertEqual(10, int(state_2.state))
|
|
||||||
self.assertEqual('Hello World',
|
|
||||||
state_2.attributes.get(ATTR_FRIENDLY_NAME))
|
|
||||||
self.assertEqual('mdi:work', state_2.attributes.get(ATTR_ICON))
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_initial_state_overrules_restore_state(hass):
|
def test_initial_state_overrules_restore_state(hass):
|
|
@ -1,4 +1,4 @@
|
||||||
"""Test fan component plaforms."""
|
"""Tests for fan platforms."""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue