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