test_avatto_blinds.py 4.7 KB

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