mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
This commit is contained in:
parent
9189cbdc8b
commit
09fec29537
@ -73,7 +73,7 @@ FAN_TURN_ON_SCHEMA = vol.Schema({
|
|||||||
}) # type: dict
|
}) # type: dict
|
||||||
|
|
||||||
FAN_TURN_OFF_SCHEMA = vol.Schema({
|
FAN_TURN_OFF_SCHEMA = vol.Schema({
|
||||||
vol.Required(ATTR_ENTITY_ID): cv.entity_ids
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids
|
||||||
}) # type: dict
|
}) # type: dict
|
||||||
|
|
||||||
FAN_OSCILLATE_SCHEMA = vol.Schema({
|
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:
|
def turn_off(hass, entity_id: str=None) -> None:
|
||||||
"""Turn all or specified fan off."""
|
"""Turn all or specified fan off."""
|
||||||
data = {
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
ATTR_ENTITY_ID: entity_id,
|
|
||||||
}
|
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||||
|
|
||||||
|
@ -56,6 +56,18 @@ class TestDemoFan(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
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):
|
def test_set_direction(self):
|
||||||
"""Test setting the direction of the device."""
|
"""Test setting the direction of the device."""
|
||||||
self.assertEqual(STATE_OFF, self.get_entity().state)
|
self.assertEqual(STATE_OFF, self.get_entity().state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user