test_m027_curtain.py 4.6 KB

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