4
0

test_simple_blinds.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. """Tests for the simple blinds controller."""
  2. from homeassistant.components.cover import (
  3. CoverDeviceClass,
  4. CoverEntityFeature,
  5. )
  6. from ..const import SIMPLE_BLINDS_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from .base_device_tests import TuyaDeviceTestCase
  9. COMMAND_DPS = "1"
  10. POSITION_DPS = "2"
  11. BACKMODE_DPS = "5"
  12. ACTION_DPS = "7"
  13. class TestSimpleBlinds(TuyaDeviceTestCase):
  14. __test__ = True
  15. def setUp(self):
  16. self.setUpForConfig("simple_blinds.yaml", SIMPLE_BLINDS_PAYLOAD)
  17. self.subject = self.entities["cover"]
  18. def test_device_class_is_blind(self):
  19. self.assertEqual(self.subject.device_class, CoverDeviceClass.BLIND)
  20. def test_supported_features(self):
  21. self.assertEqual(
  22. self.subject.supported_features,
  23. (
  24. CoverEntityFeature.OPEN
  25. | CoverEntityFeature.CLOSE
  26. | CoverEntityFeature.SET_POSITION
  27. | CoverEntityFeature.STOP
  28. ),
  29. )
  30. def test_current_cover_position(self):
  31. self.dps[POSITION_DPS] = 47
  32. self.assertEqual(self.subject.current_cover_position, 53)
  33. def test_is_opening(self):
  34. self.dps[COMMAND_DPS] = "open"
  35. self.dps[POSITION_DPS] = 0
  36. self.assertFalse(self.subject.is_opening)
  37. self.dps[POSITION_DPS] = 50
  38. self.assertTrue(self.subject.is_opening)
  39. self.dps[COMMAND_DPS] = "close"
  40. self.assertFalse(self.subject.is_opening)
  41. self.dps[COMMAND_DPS] = "stop"
  42. self.assertFalse(self.subject.is_opening)
  43. def test_is_closing(self):
  44. self.dps[COMMAND_DPS] = "close"
  45. self.dps[POSITION_DPS] = 100
  46. self.assertFalse(self.subject.is_closing)
  47. self.dps[POSITION_DPS] = 50
  48. self.assertTrue(self.subject.is_closing)
  49. self.dps[COMMAND_DPS] = "open"
  50. self.assertFalse(self.subject.is_closing)
  51. self.dps[COMMAND_DPS] = "stop"
  52. self.assertFalse(self.subject.is_closing)
  53. def test_is_closed(self):
  54. self.dps[COMMAND_DPS] = "close"
  55. self.dps[POSITION_DPS] = 0
  56. self.assertFalse(self.subject.is_closed)
  57. self.dps[POSITION_DPS] = 100
  58. self.assertTrue(self.subject.is_closed)
  59. self.dps[COMMAND_DPS] = "stop"
  60. self.assertIsNone(self.subject.is_closed)
  61. async def test_open_cover(self):
  62. async with assert_device_properties_set(
  63. self.subject._device,
  64. {COMMAND_DPS: "open"},
  65. ):
  66. await self.subject.async_open_cover()
  67. async def test_close_cover(self):
  68. async with assert_device_properties_set(
  69. self.subject._device,
  70. {COMMAND_DPS: "close"},
  71. ):
  72. await self.subject.async_close_cover()
  73. async def test_stop_cover(self):
  74. async with assert_device_properties_set(
  75. self.subject._device,
  76. {COMMAND_DPS: "stop"},
  77. ):
  78. await self.subject.async_stop_cover()
  79. async def test_set_cover_position(self):
  80. async with assert_device_properties_set(
  81. self.subject._device,
  82. {POSITION_DPS: 23},
  83. ):
  84. await self.subject.async_set_cover_position(77)
  85. def test_extra_state_attributes(self):
  86. self.dps[BACKMODE_DPS] = False
  87. self.dps[ACTION_DPS] = "test2"
  88. self.assertDictEqual(
  89. self.subject.extra_state_attributes,
  90. {
  91. "control_back_mode": False,
  92. "work_state": "test2",
  93. },
  94. )