4
0

test_smartplug_encoded.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(BasicNumberTests, SwitchableTests, TuyaDeviceTestCase):
  16. __test__ = True
  17. def setUp(self):
  18. self.setUpForConfig("smartplug_encoded.yaml", SMARTPLUG_ENCODED_PAYLOAD)
  19. self.subject = self.entities.get("switch")
  20. self.setUpSwitchable(SWITCH_DPS, self.subject)
  21. self.setUpBasicNumber(
  22. TIMER_DPS,
  23. self.entities.get("number_timer"),
  24. max=1440.0,
  25. unit=TIME_MINUTES,
  26. scale=60,
  27. )
  28. self.mark_secondary(["number_timer"])
  29. def test_device_class_is_outlet(self):
  30. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  31. def test_extra_state_attributes_set(self):
  32. self.dps[UNKNOWN101_DPS] = "101"
  33. self.dps[UNKNOWN102_DPS] = "102"
  34. self.dps[UNKNOWN103_DPS] = "103"
  35. self.assertDictEqual(
  36. self.subject.extra_state_attributes,
  37. {
  38. "unknown_101": "101",
  39. "unknown_102": "102",
  40. "unknown_103": "103",
  41. },
  42. )