test_qs_c01_curtain.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. """Tests for the QS C01 curtain module."""
  2. from homeassistant.components.cover import CoverDeviceClass, CoverEntityFeature
  3. from homeassistant.const import UnitOfTime
  4. from ..const import QS_C01_CURTAIN_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from ..mixins.number import BasicNumberTests
  7. from ..mixins.select import BasicSelectTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. COMMAND_DPS = "1"
  10. POSITION_DPS = "2"
  11. BACKMODE_DPS = "8"
  12. TRAVELTIME_DPS = "10"
  13. class TestQSC01Curtains(BasicNumberTests, BasicSelectTests, TuyaDeviceTestCase):
  14. __test__ = True
  15. def setUp(self):
  16. self.setUpForConfig("qs_c01_curtain.yaml", QS_C01_CURTAIN_PAYLOAD)
  17. self.subject = self.entities["cover_curtain"]
  18. self.setUpBasicNumber(
  19. TRAVELTIME_DPS,
  20. self.entities.get("number_travel_time"),
  21. min=1,
  22. max=60,
  23. unit=UnitOfTime.SECONDS,
  24. )
  25. self.setUpBasicSelect(
  26. BACKMODE_DPS,
  27. self.entities.get("select_motor_reverse_mode"),
  28. {
  29. "forward": "Forward",
  30. "back": "Back",
  31. },
  32. ),
  33. self.mark_secondary(["number_travel_time", "select_motor_reverse_mode"])
  34. def test_device_class_is_curtain(self):
  35. self.assertEqual(self.subject.device_class, CoverDeviceClass.CURTAIN)
  36. def test_supported_features(self):
  37. self.assertEqual(
  38. self.subject.supported_features,
  39. (
  40. CoverEntityFeature.OPEN
  41. | CoverEntityFeature.CLOSE
  42. | CoverEntityFeature.SET_POSITION
  43. | CoverEntityFeature.STOP
  44. ),
  45. )
  46. def test_current_cover_position(self):
  47. self.dps[POSITION_DPS] = 47
  48. self.assertEqual(self.subject.current_cover_position, 47)
  49. def test_is_opening(self):
  50. self.dps[COMMAND_DPS] = "open"
  51. self.dps[POSITION_DPS] = 100
  52. self.assertFalse(self.subject.is_opening)
  53. self.dps[POSITION_DPS] = 50
  54. self.assertTrue(self.subject.is_opening)
  55. self.dps[COMMAND_DPS] = "close"
  56. self.assertFalse(self.subject.is_opening)
  57. self.dps[COMMAND_DPS] = "stop"
  58. self.assertFalse(self.subject.is_opening)
  59. def test_is_closing(self):
  60. self.dps[COMMAND_DPS] = "close"
  61. self.dps[POSITION_DPS] = 0
  62. self.assertFalse(self.subject.is_closing)
  63. self.dps[POSITION_DPS] = 50
  64. self.assertTrue(self.subject.is_closing)
  65. self.dps[COMMAND_DPS] = "open"
  66. self.assertFalse(self.subject.is_closing)
  67. self.dps[COMMAND_DPS] = "stop"
  68. self.assertFalse(self.subject.is_closing)
  69. def test_is_closed(self):
  70. self.dps[COMMAND_DPS] = "close"
  71. self.dps[POSITION_DPS] = 100
  72. self.assertFalse(self.subject.is_closed)
  73. self.dps[POSITION_DPS] = 0
  74. self.assertTrue(self.subject.is_closed)
  75. async def test_open_cover(self):
  76. async with assert_device_properties_set(
  77. self.subject._device,
  78. {COMMAND_DPS: "open"},
  79. ):
  80. await self.subject.async_open_cover()
  81. async def test_close_cover(self):
  82. async with assert_device_properties_set(
  83. self.subject._device,
  84. {COMMAND_DPS: "close"},
  85. ):
  86. await self.subject.async_close_cover()
  87. async def test_stop_cover(self):
  88. async with assert_device_properties_set(
  89. self.subject._device,
  90. {COMMAND_DPS: "stop"},
  91. ):
  92. await self.subject.async_stop_cover()
  93. async def test_set_cover_position(self):
  94. async with assert_device_properties_set(
  95. self.subject._device,
  96. {POSITION_DPS: 20},
  97. ):
  98. # step is 10, so expect rounding to 20
  99. await self.subject.async_set_cover_position(23)