test_simple_blinds.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. """Tests for the simple blinds controller."""
  2. from homeassistant.components.cover import (
  3. CoverDeviceClass,
  4. SUPPORT_CLOSE,
  5. SUPPORT_OPEN,
  6. SUPPORT_SET_POSITION,
  7. SUPPORT_STOP,
  8. )
  9. from ..const import SIMPLE_BLINDS_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from .base_device_tests import TuyaDeviceTestCase
  12. COMMAND_DPS = "1"
  13. POSITION_DPS = "2"
  14. BACKMODE_DPS = "5"
  15. ACTION_DPS = "7"
  16. class TestSimpleBlinds(TuyaDeviceTestCase):
  17. __test__ = True
  18. def setUp(self):
  19. self.setUpForConfig("simple_blinds.yaml", SIMPLE_BLINDS_PAYLOAD)
  20. self.subject = self.entities["cover"]
  21. def test_device_class_is_blind(self):
  22. self.assertEqual(self.subject.device_class, CoverDeviceClass.BLIND)
  23. def test_supported_features(self):
  24. self.assertEqual(
  25. self.subject.supported_features,
  26. SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION | SUPPORT_STOP,
  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.assertTrue(self.subject.is_opening)
  37. self.dps[COMMAND_DPS] = "close"
  38. self.assertFalse(self.subject.is_opening)
  39. self.dps[COMMAND_DPS] = "stop"
  40. self.assertFalse(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.assertTrue(self.subject.is_closing)
  47. self.dps[COMMAND_DPS] = "open"
  48. self.assertFalse(self.subject.is_closing)
  49. self.dps[COMMAND_DPS] = "stop"
  50. self.assertFalse(self.subject.is_closing)
  51. def test_is_closed(self):
  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. async def test_open_cover(self):
  57. async with assert_device_properties_set(
  58. self.subject._device,
  59. {COMMAND_DPS: "open"},
  60. ):
  61. await self.subject.async_open_cover()
  62. async def test_close_cover(self):
  63. async with assert_device_properties_set(
  64. self.subject._device,
  65. {COMMAND_DPS: "close"},
  66. ):
  67. await self.subject.async_close_cover()
  68. async def test_stop_cover(self):
  69. async with assert_device_properties_set(
  70. self.subject._device,
  71. {COMMAND_DPS: "stop"},
  72. ):
  73. await self.subject.async_stop_cover()
  74. async def test_set_cover_position(self):
  75. async with assert_device_properties_set(
  76. self.subject._device,
  77. {POSITION_DPS: 23},
  78. ):
  79. await self.subject.async_set_cover_position(77)
  80. def test_extra_state_attributes(self):
  81. self.dps[BACKMODE_DPS] = False
  82. self.dps[ACTION_DPS] = "test2"
  83. self.assertDictEqual(
  84. self.subject.extra_state_attributes,
  85. {
  86. "control_back_mode": False,
  87. "work_state": "test2",
  88. },
  89. )