test_m027_curtain.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. """Tests for the M027 curtain module."""
  2. from homeassistant.components.cover import CoverDeviceClass, CoverEntityFeature
  3. from homeassistant.const import UnitOfTime
  4. from ..const import M027_CURTAIN_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from ..mixins.select import BasicSelectTests
  7. from ..mixins.sensor import MultiSensorTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. COMMAND_DPS = "1"
  10. POSITION_DPS = "2"
  11. CURRENTPOS_DPS = "3"
  12. MODE_DPS = "4"
  13. ACTION_DPS = "7"
  14. TIMER_DPS = "9"
  15. TRAVELTIME_DPS = "10"
  16. UNKNOWN12_DPS = "12"
  17. UNKNOWN101_DPS = "101"
  18. class TestM027Curtains(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
  19. __test__ = True
  20. def setUp(self):
  21. self.setUpForConfig("m027_curtain.yaml", M027_CURTAIN_PAYLOAD)
  22. self.subject = self.entities["cover_curtain"]
  23. self.setUpMultiSensors(
  24. [
  25. {
  26. "dps": TRAVELTIME_DPS,
  27. "name": "sensor_travel_time",
  28. "min": 1,
  29. "max": 120000,
  30. "unit": UnitOfTime.MILLISECONDS,
  31. },
  32. {
  33. "dps": TIMER_DPS,
  34. "name": "sensor_time_remaining",
  35. "min": 0,
  36. "max": 86400,
  37. "unit": UnitOfTime.SECONDS,
  38. },
  39. ]
  40. )
  41. self.setUpBasicSelect(
  42. MODE_DPS,
  43. self.entities.get("select_mode"),
  44. {
  45. "morning": "Morning",
  46. "night": "Night",
  47. },
  48. ),
  49. self.mark_secondary(
  50. [
  51. "binary_sensor_fault",
  52. "select_mode",
  53. "sensor_time_remaining",
  54. "sensor_travel_time",
  55. ]
  56. )
  57. def test_device_class_is_curtain(self):
  58. self.assertEqual(self.subject.device_class, CoverDeviceClass.CURTAIN)
  59. def test_supported_features(self):
  60. self.assertEqual(
  61. self.subject.supported_features,
  62. (
  63. CoverEntityFeature.OPEN
  64. | CoverEntityFeature.CLOSE
  65. | CoverEntityFeature.SET_POSITION
  66. | CoverEntityFeature.STOP
  67. ),
  68. )
  69. def test_current_cover_position(self):
  70. self.dps[CURRENTPOS_DPS] = 47
  71. self.assertEqual(self.subject.current_cover_position, 47)
  72. def test_is_opening(self):
  73. self.dps[ACTION_DPS] = "opening"
  74. self.dps[CURRENTPOS_DPS] = 100
  75. self.assertFalse(self.subject.is_opening)
  76. self.dps[CURRENTPOS_DPS] = 50
  77. self.assertTrue(self.subject.is_opening)
  78. self.dps[ACTION_DPS] = "closing"
  79. self.assertFalse(self.subject.is_opening)
  80. self.dps[ACTION_DPS] = "opening"
  81. self.dps[CURRENTPOS_DPS] = None
  82. self.assertFalse(self.subject.is_opening)
  83. def test_is_closing(self):
  84. self.dps[ACTION_DPS] = "closing"
  85. self.dps[CURRENTPOS_DPS] = 0
  86. self.assertFalse(self.subject.is_closing)
  87. self.dps[CURRENTPOS_DPS] = 50
  88. self.assertTrue(self.subject.is_closing)
  89. self.dps[ACTION_DPS] = "opening"
  90. self.assertFalse(self.subject.is_closing)
  91. self.dps[ACTION_DPS] = "closing"
  92. self.dps[CURRENTPOS_DPS] = None
  93. self.assertFalse(self.subject.is_closing)
  94. def test_is_closed(self):
  95. self.dps[CURRENTPOS_DPS] = 100
  96. self.assertFalse(self.subject.is_closed)
  97. self.dps[CURRENTPOS_DPS] = 0
  98. self.assertTrue(self.subject.is_closed)
  99. self.dps[ACTION_DPS] = "closing"
  100. self.dps[CURRENTPOS_DPS] = None
  101. self.assertTrue(self.subject.is_closed)
  102. async def test_open_cover(self):
  103. async with assert_device_properties_set(
  104. self.subject._device,
  105. {COMMAND_DPS: "open"},
  106. ):
  107. await self.subject.async_open_cover()
  108. async def test_close_cover(self):
  109. async with assert_device_properties_set(
  110. self.subject._device,
  111. {COMMAND_DPS: "close"},
  112. ):
  113. await self.subject.async_close_cover()
  114. async def test_stop_cover(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {COMMAND_DPS: "stop"},
  118. ):
  119. await self.subject.async_stop_cover()
  120. async def test_set_cover_position(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {POSITION_DPS: 23},
  124. ):
  125. await self.subject.async_set_cover_position(23)