mirror of
https://github.com/elisspace/core.git
synced 2026-10-02 15:30:00 +00:00
Fix X10 commands for mochad light turn on (#11146)
* Fix X10 commands for mochad light turn on This commit attempts to address issues that a lot of people are having with the x10 light component. Originally this was written to use the xdim (extended dim) X10 command. However, not every X10 dimmer device supports the xdim command. Additionally, it turns out the number of dim/brighness levels the X10 device supports is device specific and there is no way to detect this (given the mostly 1 way nature of X10) To address these issues, this commit removes the usage of xdim and instead relies on using the 'on' command and the 'dim' command. This should work on all x10 light devices. In an attempt to address the different dim/brightness levels supported by different devices this commit also adds a new optional config value, 'brightness_levels', to specify if it's either 32, 64, or 256. By default 32 levels are used as this is the normal case and what is documented by mochad. Fixes #8943 * make code more readable * fix style * fix lint * fix tests
This commit is contained in:
@@ -60,7 +60,8 @@ class TestMochadLight(unittest.TestCase):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
controller_mock = mock.MagicMock()
|
||||
dev_dict = {'address': 'a1', 'name': 'fake_light'}
|
||||
dev_dict = {'address': 'a1', 'name': 'fake_light',
|
||||
'brightness_levels': 32}
|
||||
self.light = mochad.MochadLight(self.hass, controller_mock,
|
||||
dev_dict)
|
||||
|
||||
@@ -72,6 +73,39 @@ class TestMochadLight(unittest.TestCase):
|
||||
"""Test the name."""
|
||||
self.assertEqual('fake_light', self.light.name)
|
||||
|
||||
def test_turn_on_with_no_brightness(self):
|
||||
"""Test turn_on."""
|
||||
self.light.turn_on()
|
||||
self.light.device.send_cmd.assert_called_once_with('on')
|
||||
|
||||
def test_turn_on_with_brightness(self):
|
||||
"""Test turn_on."""
|
||||
self.light.turn_on(brightness=45)
|
||||
self.light.device.send_cmd.assert_has_calls(
|
||||
[mock.call('on'), mock.call('dim 25')])
|
||||
|
||||
def test_turn_off(self):
|
||||
"""Test turn_off."""
|
||||
self.light.turn_off()
|
||||
self.light.device.send_cmd.assert_called_once_with('off')
|
||||
|
||||
|
||||
class TestMochadLight256Levels(unittest.TestCase):
|
||||
"""Test for mochad light platform."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
controller_mock = mock.MagicMock()
|
||||
dev_dict = {'address': 'a1', 'name': 'fake_light',
|
||||
'brightness_levels': 256}
|
||||
self.light = mochad.MochadLight(self.hass, controller_mock,
|
||||
dev_dict)
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_turn_on_with_no_brightness(self):
|
||||
"""Test turn_on."""
|
||||
self.light.turn_on()
|
||||
@@ -86,3 +120,35 @@ class TestMochadLight(unittest.TestCase):
|
||||
"""Test turn_off."""
|
||||
self.light.turn_off()
|
||||
self.light.device.send_cmd.assert_called_once_with('off')
|
||||
|
||||
|
||||
class TestMochadLight64Levels(unittest.TestCase):
|
||||
"""Test for mochad light platform."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
controller_mock = mock.MagicMock()
|
||||
dev_dict = {'address': 'a1', 'name': 'fake_light',
|
||||
'brightness_levels': 64}
|
||||
self.light = mochad.MochadLight(self.hass, controller_mock,
|
||||
dev_dict)
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_turn_on_with_no_brightness(self):
|
||||
"""Test turn_on."""
|
||||
self.light.turn_on()
|
||||
self.light.device.send_cmd.assert_called_once_with('xdim 63')
|
||||
|
||||
def test_turn_on_with_brightness(self):
|
||||
"""Test turn_on."""
|
||||
self.light.turn_on(brightness=45)
|
||||
self.light.device.send_cmd.assert_called_once_with('xdim 11')
|
||||
|
||||
def test_turn_off(self):
|
||||
"""Test turn_off."""
|
||||
self.light.turn_off()
|
||||
self.light.device.send_cmd.assert_called_once_with('off')
|
||||
|
||||
Reference in New Issue
Block a user