test_smartplug_encoded.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """Tests for the switch entity."""
  2. from homeassistant.components.switch import SwitchDeviceClass
  3. from homeassistant.const import (
  4. TIME_MINUTES,
  5. )
  6. from ..const import SMARTPLUG_ENCODED_PAYLOAD
  7. from ..mixins.number import BasicNumberTests
  8. from ..mixins.switch import SwitchableTests
  9. from .base_device_tests import TuyaDeviceTestCase
  10. SWITCH_DPS = "1"
  11. TIMER_DPS = "11"
  12. UNKNOWN101_DPS = "101"
  13. UNKNOWN102_DPS = "102"
  14. UNKNOWN103_DPS = "103"
  15. class TestSwitchEncoded(
  16. BasicNumberTests, SwitchableTests, TuyaDeviceTestCase
  17. ):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig("smartplug_encoded.yaml", SMARTPLUG_ENCODED_PAYLOAD)
  21. self.subject = self.entities.get("switch")
  22. self.setUpSwitchable(SWITCH_DPS, self.subject)
  23. self.setUpBasicNumber(
  24. TIMER_DPS,
  25. self.entities.get("number_timer"),
  26. max=1440.0,
  27. unit=TIME_MINUTES,
  28. scale=60,
  29. )
  30. self.mark_secondary(["number_timer"])
  31. def test_device_class_is_outlet(self):
  32. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  33. def test_extra_state_attributes_set(self):
  34. self.dps[UNKNOWN101_DPS] = "101"
  35. self.dps[UNKNOWN102_DPS] = "102"
  36. self.dps[UNKNOWN103_DPS] = "103"
  37. self.assertDictEqual(
  38. self.subject.extra_state_attributes,
  39. {
  40. "unknown_101": "101",
  41. "unknown_102": "102",
  42. "unknown_103": "103",
  43. },
  44. )