From a5d5f3f7276915469b1d747ce63d1c65a3e02903 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sun, 5 Nov 2017 13:51:52 +0100 Subject: [PATCH] Move counter component (#10332) * Fix docstring * Add comment * Move counter to folder * Fix missing parts * Commit it when file is saved --- .../{counter.py => counter/__init__.py} | 6 +- .../components/counter/services.yaml | 20 +++++ homeassistant/components/services.yaml | 20 ----- homeassistant/components/timer/services.yaml | 2 + tests/components/counter/__init__.py | 1 + .../{test_counter.py => counter/test_init.py} | 82 +++++++++---------- tests/components/fan/__init__.py | 2 +- 7 files changed, 68 insertions(+), 65 deletions(-) rename homeassistant/components/{counter.py => counter/__init__.py} (96%) create mode 100644 homeassistant/components/counter/services.yaml create mode 100644 tests/components/counter/__init__.py rename tests/components/{test_counter.py => counter/test_init.py} (100%) diff --git a/homeassistant/components/counter.py b/homeassistant/components/counter/__init__.py similarity index 96% rename from homeassistant/components/counter.py rename to homeassistant/components/counter/__init__.py index 64421306644..aee94c069f6 100644 --- a/homeassistant/components/counter.py +++ b/homeassistant/components/counter/__init__.py @@ -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 diff --git a/homeassistant/components/counter/services.yaml b/homeassistant/components/counter/services.yaml new file mode 100644 index 00000000000..ef76f9b9eac --- /dev/null +++ b/homeassistant/components/counter/services.yaml @@ -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' \ No newline at end of file diff --git a/homeassistant/components/services.yaml b/homeassistant/components/services.yaml index 37829142e0c..c4e460fdb66 100644 --- a/homeassistant/components/services.yaml +++ b/homeassistant/components/services.yaml @@ -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. diff --git a/homeassistant/components/timer/services.yaml b/homeassistant/components/timer/services.yaml index f7d2c1a77b5..b299aaa8185 100644 --- a/homeassistant/components/timer/services.yaml +++ b/homeassistant/components/timer/services.yaml @@ -1,3 +1,5 @@ +# Describes the format for available timer services + start: description: Start a timer. diff --git a/tests/components/counter/__init__.py b/tests/components/counter/__init__.py new file mode 100644 index 00000000000..7ebe8e7d7b5 --- /dev/null +++ b/tests/components/counter/__init__.py @@ -0,0 +1 @@ +"""Tests for the counter component.""" diff --git a/tests/components/test_counter.py b/tests/components/counter/test_init.py similarity index 100% rename from tests/components/test_counter.py rename to tests/components/counter/test_init.py index 8dc04f0e76a..f4c6ee9c7da 100644 --- a/tests/components/test_counter.py +++ b/tests/components/counter/test_init.py @@ -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): diff --git a/tests/components/fan/__init__.py b/tests/components/fan/__init__.py index 54ed1fcc505..28ae7f4e249 100644 --- a/tests/components/fan/__init__.py +++ b/tests/components/fan/__init__.py @@ -1,4 +1,4 @@ -"""Test fan component plaforms.""" +"""Tests for fan platforms.""" import unittest