Move counter component (#10332)
* Fix docstring * Add comment * Move counter to folder * Fix missing parts * Commit it when file is saved
This commit is contained in:
parent
5be6f8ff36
commit
a5d5f3f727
7 changed files with 68 additions and 65 deletions
|
@ -140,13 +140,13 @@ def async_setup(hass, config):
|
|||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_INCREMENT, async_handler_service,
|
||||
descriptions[DOMAIN][SERVICE_INCREMENT], SERVICE_SCHEMA)
|
||||
descriptions[SERVICE_INCREMENT], SERVICE_SCHEMA)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_DECREMENT, async_handler_service,
|
||||
descriptions[DOMAIN][SERVICE_DECREMENT], SERVICE_SCHEMA)
|
||||
descriptions[SERVICE_DECREMENT], SERVICE_SCHEMA)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_RESET, async_handler_service,
|
||||
descriptions[DOMAIN][SERVICE_RESET], SERVICE_SCHEMA)
|
||||
descriptions[SERVICE_RESET], SERVICE_SCHEMA)
|
||||
|
||||
yield from component.async_add_entities(entities)
|
||||
return True
|
20
homeassistant/components/counter/services.yaml
Normal file
20
homeassistant/components/counter/services.yaml
Normal file
|
@ -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.
|
||||
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:
|
||||
change_setting:
|
||||
description: Change an Abode system setting.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Describes the format for available timer services
|
||||
|
||||
start:
|
||||
description: Start a timer.
|
||||
|
||||
|
|
1
tests/components/counter/__init__.py
Normal file
1
tests/components/counter/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
"""Tests for the counter component."""
|
|
@ -42,6 +42,47 @@ class TestCounter(unittest.TestCase):
|
|||
self.assertFalse(
|
||||
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):
|
||||
"""Test increment, decrement, and reset methods."""
|
||||
config = {
|
||||
|
@ -118,47 +159,6 @@ class TestCounter(unittest.TestCase):
|
|||
state = self.hass.states.get(entity_id)
|
||||
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
|
||||
def test_initial_state_overrules_restore_state(hass):
|
|
@ -1,4 +1,4 @@
|
|||
"""Test fan component plaforms."""
|
||||
"""Tests for fan platforms."""
|
||||
|
||||
import unittest
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue