test_m027_curtain.py 4.5 KB

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