test_m027_curtain.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. class TestM027Curtains(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
  20. __test__ = True
  21. def setUp(self):
  22. self.setUpForConfig("m027_curtain.yaml", M027_CURTAIN_PAYLOAD)
  23. self.subject = self.entities["cover"]
  24. self.setUpMultiSensors(
  25. [
  26. {
  27. "dps": TRAVELTIME_DPS,
  28. "name": "sensor_travel_time",
  29. "min": 1,
  30. "max": 120000,
  31. "unit": TIME_MILLISECONDS,
  32. },
  33. {
  34. "dps": TIMER_DPS,
  35. "name": "sensor_time_remaining",
  36. "min": 0,
  37. "max": 86400,
  38. "unit": TIME_SECONDS,
  39. },
  40. ]
  41. )
  42. self.setUpBasicSelect(
  43. MODE_DPS,
  44. self.entities.get("select_mode"),
  45. {
  46. "morning": "Morning",
  47. "night": "Night",
  48. },
  49. ),
  50. self.mark_secondary(
  51. ["sensor_travel_time", "sensor_time_remaining", "select_mode"]
  52. )
  53. def test_device_class_is_curtain(self):
  54. self.assertEqual(self.subject.device_class, CoverDeviceClass.CURTAIN)
  55. def test_supported_features(self):
  56. self.assertEqual(
  57. self.subject.supported_features,
  58. (
  59. CoverEntityFeature.OPEN
  60. | CoverEntityFeature.CLOSE
  61. | CoverEntityFeature.SET_POSITION
  62. | CoverEntityFeature.STOP
  63. ),
  64. )
  65. def test_current_cover_position(self):
  66. self.dps[CURRENTPOS_DPS] = 47
  67. self.assertEqual(self.subject.current_cover_position, 47)
  68. def test_is_opening(self):
  69. self.dps[ACTION_DPS] = "opening"
  70. self.dps[CURRENTPOS_DPS] = 100
  71. self.assertFalse(self.subject.is_opening)
  72. self.dps[CURRENTPOS_DPS] = 50
  73. self.assertTrue(self.subject.is_opening)
  74. self.dps[ACTION_DPS] = "closing"
  75. self.assertFalse(self.subject.is_opening)
  76. def test_is_closing(self):
  77. self.dps[ACTION_DPS] = "closing"
  78. self.dps[CURRENTPOS_DPS] = 0
  79. self.assertFalse(self.subject.is_closing)
  80. self.dps[CURRENTPOS_DPS] = 50
  81. self.assertTrue(self.subject.is_closing)
  82. self.dps[ACTION_DPS] = "opening"
  83. self.assertFalse(self.subject.is_closing)
  84. def test_is_closed(self):
  85. self.dps[CURRENTPOS_DPS] = 100
  86. self.assertFalse(self.subject.is_closed)
  87. self.dps[CURRENTPOS_DPS] = 0
  88. self.assertTrue(self.subject.is_closed)
  89. async def test_open_cover(self):
  90. async with assert_device_properties_set(
  91. self.subject._device,
  92. {COMMAND_DPS: "open"},
  93. ):
  94. await self.subject.async_open_cover()
  95. async def test_close_cover(self):
  96. async with assert_device_properties_set(
  97. self.subject._device,
  98. {COMMAND_DPS: "close"},
  99. ):
  100. await self.subject.async_close_cover()
  101. async def test_stop_cover(self):
  102. async with assert_device_properties_set(
  103. self.subject._device,
  104. {COMMAND_DPS: "stop"},
  105. ):
  106. await self.subject.async_stop_cover()
  107. async def test_set_cover_position(self):
  108. async with assert_device_properties_set(
  109. self.subject._device,
  110. {POSITION_DPS: 23},
  111. ):
  112. await self.subject.async_set_cover_position(23)