Merge pull request #1551 from w1ll1am23/command_line_assumed
Added assumed state to command_line switchpull/1603/head
commit
70ce179224
|
@ -33,6 +33,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||
add_devices_callback(devices)
|
||||
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
class CommandSwitch(SwitchDevice):
|
||||
"""Representation a switch that can be toggled using shell commands."""
|
||||
|
||||
|
@ -92,6 +93,11 @@ class CommandSwitch(SwitchDevice):
|
|||
"""Return true if device is on."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
"""Return true if we do optimistic updates."""
|
||||
return self._command_state is False
|
||||
|
||||
def _query_state(self):
|
||||
"""Query for state."""
|
||||
if not self._command_state:
|
||||
|
|
|
@ -6,6 +6,7 @@ import unittest
|
|||
|
||||
from homeassistant.const import STATE_ON, STATE_OFF
|
||||
import homeassistant.components.switch as switch
|
||||
import homeassistant.components.switch.command_line as command_line
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
@ -155,3 +156,21 @@ class TestCommandSwitch(unittest.TestCase):
|
|||
|
||||
state = self.hass.states.get('switch.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
|
||||
def test_assumed_state_should_be_true_if_command_state_is_false(self):
|
||||
"""Test with state value."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
# Set state command to false
|
||||
statecmd = False
|
||||
|
||||
no_state_device = command_line.CommandSwitch(self.hass, "Test", "echo",
|
||||
"echo", statecmd, None)
|
||||
self.assertTrue(no_state_device.assumed_state)
|
||||
|
||||
# Set state command
|
||||
statecmd = 'cat {}'
|
||||
|
||||
state_device = command_line.CommandSwitch(self.hass, "Test", "echo",
|
||||
"echo", statecmd, None)
|
||||
self.assertFalse(state_device.assumed_state)
|
||||
|
|
Loading…
Reference in New Issue