test_avatto_blinds.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. """Tests for the Avatto roller blinds controller."""
  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 AVATTO_BLINDS_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_DP = "1"
  11. POSITION_DP = "2"
  12. CURRENTPOS_DP = "3"
  13. BACK_DP = "5"
  14. ACTION_DP = "7"
  15. TIMER_DP = "8"
  16. COUNTDOWN_DP = "9"
  17. TRAVELTIME_DP = "11"
  18. class TestAvattoBlinds(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
  19. __test__ = True
  20. def setUp(self):
  21. self.setUpForConfig("avatto_roller_blinds.yaml", AVATTO_BLINDS_PAYLOAD)
  22. self.subject = self.entities["cover_blind"]
  23. self.setUpMultiSensors(
  24. [
  25. {
  26. "dps": TRAVELTIME_DP,
  27. "name": "sensor_travel_time",
  28. "min": 0,
  29. "max": 120000,
  30. "unit": UnitOfTime.MILLISECONDS,
  31. },
  32. {
  33. "dps": COUNTDOWN_DP,
  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. TIMER_DP,
  44. self.entities.get("select_timer"),
  45. {
  46. "cancel": "cancel",
  47. "1": "1h",
  48. "2": "2h",
  49. "3": "3h",
  50. "4": "4h",
  51. },
  52. )
  53. self.mark_secondary(
  54. [
  55. "sensor_travel_time",
  56. "sensor_time_remaining",
  57. "select_timer",
  58. "select_direction",
  59. "binary_sensor_problem",
  60. ]
  61. )
  62. def test_device_class_is_blind(self):
  63. self.assertEqual(self.subject.device_class, CoverDeviceClass.BLIND)
  64. def test_supported_features(self):
  65. self.assertEqual(
  66. self.subject.supported_features,
  67. (
  68. CoverEntityFeature.OPEN
  69. | CoverEntityFeature.CLOSE
  70. | CoverEntityFeature.SET_POSITION
  71. | CoverEntityFeature.STOP
  72. ),
  73. )
  74. def test_current_cover_position(self):
  75. self.dps[CURRENTPOS_DP] = 47
  76. self.assertEqual(self.subject.current_cover_position, 53)
  77. def test_is_opening(self):
  78. self.dps[COMMAND_DP] = "stop"
  79. self.dps[ACTION_DP] = "opening"
  80. self.dps[CURRENTPOS_DP] = 0
  81. self.assertFalse(self.subject.is_opening)
  82. self.dps[CURRENTPOS_DP] = 50
  83. self.assertTrue(self.subject.is_opening)
  84. self.dps[ACTION_DP] = "closing"
  85. self.assertFalse(self.subject.is_opening)
  86. self.dps[ACTION_DP] = "opening"
  87. self.dps[CURRENTPOS_DP] = None
  88. self.assertFalse(self.subject.is_opening)
  89. def test_is_closing(self):
  90. self.dps[COMMAND_DP] = "stop"
  91. self.dps[ACTION_DP] = "closing"
  92. self.dps[CURRENTPOS_DP] = 100
  93. self.assertFalse(self.subject.is_closing)
  94. self.dps[CURRENTPOS_DP] = 50
  95. self.assertTrue(self.subject.is_closing)
  96. self.dps[ACTION_DP] = "opening"
  97. self.assertFalse(self.subject.is_closing)
  98. self.dps[ACTION_DP] = "closing"
  99. self.dps[CURRENTPOS_DP] = None
  100. self.assertFalse(self.subject.is_closing)
  101. def test_is_closed(self):
  102. self.dps[COMMAND_DP] = "stop"
  103. self.dps[CURRENTPOS_DP] = 0
  104. self.assertFalse(self.subject.is_closed)
  105. self.dps[CURRENTPOS_DP] = 100
  106. self.assertTrue(self.subject.is_closed)
  107. self.dps[ACTION_DP] = "closing"
  108. self.dps[CURRENTPOS_DP] = None
  109. self.assertFalse(self.subject.is_closed)
  110. async def test_open_cover(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {COMMAND_DP: "open"},
  114. ):
  115. await self.subject.async_open_cover()
  116. async def test_close_cover(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {COMMAND_DP: "close"},
  120. ):
  121. await self.subject.async_close_cover()
  122. async def test_stop_cover(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {COMMAND_DP: "stop"},
  126. ):
  127. await self.subject.async_stop_cover()
  128. async def test_set_cover_position(self):
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {POSITION_DP: 23},
  132. ):
  133. await self.subject.async_set_cover_position(77)