test_simple_blinds.py 3.5 KB

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