test_simple_blinds.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. """Tests for the simple blinds controller."""
  2. from homeassistant.components.cover import (
  3. CoverDeviceClass,
  4. CoverEntityFeature,
  5. )
  6. from ..const import SIMPLE_BLINDS_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from .base_device_tests import TuyaDeviceTestCase
  9. COMMAND_DPS = "1"
  10. POSITION_DPS = "2"
  11. BACKMODE_DPS = "5"
  12. ACTION_DPS = "7"
  13. class TestSimpleBlinds(TuyaDeviceTestCase):
  14. __test__ = True
  15. def setUp(self):
  16. self.setUpForConfig("simple_blinds.yaml", SIMPLE_BLINDS_PAYLOAD)
  17. self.subject = self.entities["cover"]
  18. def test_device_class_is_blind(self):
  19. self.assertEqual(self.subject.device_class, CoverDeviceClass.BLIND)
  20. def test_supported_features(self):
  21. self.assertEqual(
  22. self.subject.supported_features,
  23. (
  24. CoverEntityFeature.OPEN
  25. | CoverEntityFeature.CLOSE
  26. | CoverEntityFeature.SET_POSITION
  27. | CoverEntityFeature.STOP
  28. ),
  29. )
  30. def test_current_cover_position(self):
  31. self.dps[POSITION_DPS] = 47
  32. self.assertEqual(self.subject.current_cover_position, 53)
  33. def test_is_opening(self):
  34. self.dps[COMMAND_DPS] = "open"
  35. self.dps[POSITION_DPS] = 0
  36. self.assertFalse(self.subject.is_opening)
  37. self.dps[POSITION_DPS] = 50
  38. self.assertTrue(self.subject.is_opening)
  39. self.dps[COMMAND_DPS] = "close"
  40. self.assertFalse(self.subject.is_opening)
  41. self.dps[COMMAND_DPS] = "stop"
  42. self.assertFalse(self.subject.is_opening)
  43. def test_is_closing(self):
  44. self.dps[COMMAND_DPS] = "close"
  45. self.dps[POSITION_DPS] = 100
  46. self.assertFalse(self.subject.is_closing)
  47. self.dps[POSITION_DPS] = 50
  48. self.assertTrue(self.subject.is_closing)
  49. self.dps[COMMAND_DPS] = "open"
  50. self.assertFalse(self.subject.is_closing)
  51. self.dps[COMMAND_DPS] = "stop"
  52. self.assertFalse(self.subject.is_closing)
  53. def test_is_closed(self):
  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. 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. )