entity_id for service fan.turn_off is optional (#7982)

* entity id is optional

* use a simple if/else to set the data for the fan.turn_off service
pull/8020/head
Thiago Oliveira 2017-06-13 08:28:05 -07:00 committed by Pascal Vizeli
parent 9189cbdc8b
commit 09fec29537
2 changed files with 14 additions and 4 deletions

View File

@ -73,7 +73,7 @@ FAN_TURN_ON_SCHEMA = vol.Schema({
}) # type: dict
FAN_TURN_OFF_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.entity_ids
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids
}) # type: dict
FAN_OSCILLATE_SCHEMA = vol.Schema({
@ -139,9 +139,7 @@ def turn_on(hass, entity_id: str=None, speed: str=None) -> None:
def turn_off(hass, entity_id: str=None) -> None:
"""Turn all or specified fan off."""
data = {
ATTR_ENTITY_ID: entity_id,
}
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)

View File

@ -56,6 +56,18 @@ class TestDemoFan(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(STATE_OFF, self.get_entity().state)
def test_turn_off_without_entity_id(self):
"""Test turning off all fans."""
self.assertEqual(STATE_OFF, self.get_entity().state)
fan.turn_on(self.hass, FAN_ENTITY_ID)
self.hass.block_till_done()
self.assertNotEqual(STATE_OFF, self.get_entity().state)
fan.turn_off(self.hass)
self.hass.block_till_done()
self.assertEqual(STATE_OFF, self.get_entity().state)
def test_set_direction(self):
"""Test setting the direction of the device."""
self.assertEqual(STATE_OFF, self.get_entity().state)