test_simple_blinds.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. """Tests for the simple blinds controller."""
  2. from homeassistant.components.cover import CoverDeviceClass, CoverEntityFeature
  3. from ..const import SIMPLE_BLINDS_PAYLOAD
  4. from ..helpers import assert_device_properties_set
  5. from .base_device_tests import TuyaDeviceTestCase
  6. COMMAND_DPS = "1"
  7. POSITION_DPS = "2"
  8. CURRENT_POSITION = "3"
  9. BACKMODE_DPS = "5"
  10. ACTION_DPS = "7"
  11. class TestSimpleBlinds(TuyaDeviceTestCase):
  12. __test__ = True
  13. def setUp(self):
  14. self.setUpForConfig("simple_blinds.yaml", SIMPLE_BLINDS_PAYLOAD)
  15. self.subject = self.entities["cover_blind"]
  16. self.mark_secondary(["switch_reverse"])
  17. def test_device_class_is_blind(self):
  18. self.assertEqual(self.subject.device_class, CoverDeviceClass.BLIND)
  19. def test_supported_features(self):
  20. self.assertEqual(
  21. self.subject.supported_features,
  22. (
  23. CoverEntityFeature.OPEN
  24. | CoverEntityFeature.CLOSE
  25. | CoverEntityFeature.SET_POSITION
  26. | CoverEntityFeature.STOP
  27. ),
  28. )
  29. def test_current_cover_position(self):
  30. self.dps[POSITION_DPS] = 47
  31. self.assertEqual(self.subject.current_cover_position, 53)
  32. def test_is_opening(self):
  33. self.dps[COMMAND_DPS] = "open"
  34. self.dps[POSITION_DPS] = 0
  35. self.assertFalse(self.subject.is_opening)
  36. self.dps[POSITION_DPS] = 50
  37. self.assertIsNone(self.subject.is_opening)
  38. self.dps[COMMAND_DPS] = "close"
  39. self.assertIsNone(self.subject.is_opening)
  40. self.dps[COMMAND_DPS] = "stop"
  41. self.assertIsNone(self.subject.is_opening)
  42. def test_is_closing(self):
  43. self.dps[COMMAND_DPS] = "close"
  44. self.dps[POSITION_DPS] = 100
  45. self.assertFalse(self.subject.is_closing)
  46. self.dps[POSITION_DPS] = 50
  47. self.assertIsNone(self.subject.is_closing)
  48. self.dps[COMMAND_DPS] = "open"
  49. self.assertIsNone(self.subject.is_closing)
  50. self.dps[COMMAND_DPS] = "stop"
  51. self.assertIsNone(self.subject.is_closing)
  52. def test_is_closed(self):
  53. self.dps[COMMAND_DPS] = "close"
  54. self.dps[POSITION_DPS] = 0
  55. self.assertFalse(self.subject.is_closed)
  56. self.dps[POSITION_DPS] = 100
  57. self.assertTrue(self.subject.is_closed)
  58. self.dps[COMMAND_DPS] = "stop"
  59. self.assertTrue(self.subject.is_closed)
  60. async def test_open_cover(self):
  61. async with assert_device_properties_set(
  62. self.subject._device,
  63. {COMMAND_DPS: "open"},
  64. ):
  65. await self.subject.async_open_cover()
  66. async def test_close_cover(self):
  67. async with assert_device_properties_set(
  68. self.subject._device,
  69. {COMMAND_DPS: "close"},
  70. ):
  71. await self.subject.async_close_cover()
  72. async def test_stop_cover(self):
  73. async with assert_device_properties_set(
  74. self.subject._device,
  75. {COMMAND_DPS: "stop"},
  76. ):
  77. await self.subject.async_stop_cover()
  78. async def test_set_cover_position(self):
  79. async with assert_device_properties_set(
  80. self.subject._device,
  81. {POSITION_DPS: 23},
  82. ):
  83. await self.subject.async_set_cover_position(77)
  84. def test_extra_state_attributes(self):
  85. self.dps[ACTION_DPS] = "test"
  86. self.assertDictEqual(
  87. self.subject.extra_state_attributes,
  88. {
  89. "work_state": "test",
  90. },
  91. )