test_qs_c01_curtain.py 3.9 KB

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