test_m027_curtain.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """Tests for the M027 curtain module."""
  2. from homeassistant.components.cover import (
  3. CoverDeviceClass,
  4. CoverEntityFeature,
  5. )
  6. from homeassistant.const import TIME_MILLISECONDS, TIME_SECONDS
  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": TIME_MILLISECONDS,
  34. },
  35. {
  36. "dps": TIMER_DPS,
  37. "name": "sensor_time_remaining",
  38. "min": 0,
  39. "max": 86400,
  40. "unit": TIME_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. ["sensor_travel_time", "sensor_time_remaining", "select_mode"]
  54. )
  55. def test_device_class_is_curtain(self):
  56. self.assertEqual(self.subject.device_class, CoverDeviceClass.CURTAIN)
  57. def test_supported_features(self):
  58. self.assertEqual(
  59. self.subject.supported_features,
  60. (
  61. CoverEntityFeature.OPEN
  62. | CoverEntityFeature.CLOSE
  63. | CoverEntityFeature.SET_POSITION
  64. | CoverEntityFeature.STOP
  65. ),
  66. )
  67. def test_current_cover_position(self):
  68. self.dps[CURRENTPOS_DPS] = 47
  69. self.assertEqual(self.subject.current_cover_position, 47)
  70. def test_is_opening(self):
  71. self.dps[ACTION_DPS] = "opening"
  72. self.dps[CURRENTPOS_DPS] = 100
  73. self.assertFalse(self.subject.is_opening)
  74. self.dps[CURRENTPOS_DPS] = 50
  75. self.assertTrue(self.subject.is_opening)
  76. self.dps[ACTION_DPS] = "closing"
  77. self.assertFalse(self.subject.is_opening)
  78. self.dps[ACTION_DPS] = "opening"
  79. self.dps[CURRENTPOS_DPS] = None
  80. self.assertFalse(self.subject.is_opening)
  81. def test_is_closing(self):
  82. self.dps[ACTION_DPS] = "closing"
  83. self.dps[CURRENTPOS_DPS] = 0
  84. self.assertFalse(self.subject.is_closing)
  85. self.dps[CURRENTPOS_DPS] = 50
  86. self.assertTrue(self.subject.is_closing)
  87. self.dps[ACTION_DPS] = "opening"
  88. self.assertFalse(self.subject.is_closing)
  89. self.dps[ACTION_DPS] = "closing"
  90. self.dps[CURRENTPOS_DPS] = None
  91. self.assertFalse(self.subject.is_closing)
  92. def test_is_closed(self):
  93. self.dps[CURRENTPOS_DPS] = 100
  94. self.assertFalse(self.subject.is_closed)
  95. self.dps[CURRENTPOS_DPS] = 0
  96. self.assertTrue(self.subject.is_closed)
  97. self.dps[ACTION_DPS] = "closing"
  98. self.dps[CURRENTPOS_DPS] = None
  99. self.assertTrue(self.subject.is_closed)
  100. async def test_open_cover(self):
  101. async with assert_device_properties_set(
  102. self.subject._device,
  103. {COMMAND_DPS: "open"},
  104. ):
  105. await self.subject.async_open_cover()
  106. async def test_close_cover(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {COMMAND_DPS: "close"},
  110. ):
  111. await self.subject.async_close_cover()
  112. async def test_stop_cover(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {COMMAND_DPS: "stop"},
  116. ):
  117. await self.subject.async_stop_cover()
  118. async def test_set_cover_position(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {POSITION_DPS: 23},
  122. ):
  123. await self.subject.async_set_cover_position(23)