test_smartplugv2.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Tests for the switch entity."""
  2. from homeassistant.components.switch import DEVICE_CLASS_OUTLET
  3. from ..const import KOGAN_SOCKET_PAYLOAD2
  4. from ..helpers import assert_device_properties_set
  5. from .base_device_tests import SwitchableTests, TuyaDeviceTestCase
  6. SWITCH_DPS = "1"
  7. TIMER_DPS = "9"
  8. CURRENT_DPS = "18"
  9. POWER_DPS = "19"
  10. VOLTAGE_DPS = "20"
  11. class TestSwitchV2(SwitchableTests, TuyaDeviceTestCase):
  12. __test__ = True
  13. def setUp(self):
  14. self.setUpForConfig("smartplugv2.yaml", KOGAN_SOCKET_PAYLOAD2)
  15. self.subject = self.entities.get("switch")
  16. self.setUpSwitchable(SWITCH_DPS, self.subject)
  17. def test_device_class_is_outlet(self):
  18. self.assertEqual(self.subject.device_class, DEVICE_CLASS_OUTLET)
  19. def test_current_power_w(self):
  20. self.dps[POWER_DPS] = 1234
  21. self.assertEqual(self.subject.current_power_w, 123.4)
  22. def test_device_state_attributes_set(self):
  23. self.dps[TIMER_DPS] = 1
  24. self.dps[VOLTAGE_DPS] = 2350
  25. self.dps[CURRENT_DPS] = 1234
  26. self.dps[POWER_DPS] = 5678
  27. self.assertDictEqual(
  28. self.subject.device_state_attributes,
  29. {
  30. "timer": 1,
  31. "current_a": 1.234,
  32. "voltage_v": 235.0,
  33. "current_power_w": 567.8,
  34. },
  35. )