test_smartplugv2.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """Tests for the switch entity."""
  2. from homeassistant.components.sensor import SensorDeviceClass
  3. from homeassistant.components.switch import SwitchDeviceClass
  4. from homeassistant.const import (
  5. UnitOfElectricCurrent,
  6. UnitOfElectricPotential,
  7. UnitOfPower,
  8. )
  9. from ..const import KOGAN_SOCKET_PAYLOAD2
  10. from ..mixins.sensor import MultiSensorTests
  11. from ..mixins.switch import SwitchableTests
  12. from .base_device_tests import TuyaDeviceTestCase
  13. SWITCH_DPS = "1"
  14. TIMER_DPS = "9"
  15. CURRENT_DPS = "18"
  16. POWER_DPS = "19"
  17. VOLTAGE_DPS = "20"
  18. class TestSwitchV2(
  19. MultiSensorTests,
  20. SwitchableTests,
  21. TuyaDeviceTestCase,
  22. ):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig("smartplugv2.yaml", KOGAN_SOCKET_PAYLOAD2)
  26. self.subject = self.entities.get("switch_outlet")
  27. self.setUpSwitchable(SWITCH_DPS, self.subject)
  28. self.setUpMultiSensors(
  29. [
  30. {
  31. "name": "sensor_voltage",
  32. "dps": VOLTAGE_DPS,
  33. "unit": UnitOfElectricPotential.VOLT,
  34. "device_class": SensorDeviceClass.VOLTAGE,
  35. "state_class": "measurement",
  36. "testdata": (2300, 230.0),
  37. },
  38. {
  39. "name": "sensor_current",
  40. "dps": CURRENT_DPS,
  41. "unit": UnitOfElectricCurrent.MILLIAMPERE,
  42. "device_class": SensorDeviceClass.CURRENT,
  43. "state_class": "measurement",
  44. },
  45. {
  46. "name": "sensor_power",
  47. "dps": POWER_DPS,
  48. "unit": UnitOfPower.WATT,
  49. "device_class": SensorDeviceClass.POWER,
  50. "state_class": "measurement",
  51. "testdata": (1234, 123.4),
  52. },
  53. ]
  54. )
  55. self.mark_secondary(
  56. [
  57. "binary_sensor_problem",
  58. "sensor_current",
  59. "sensor_power",
  60. "sensor_voltage",
  61. "time_timer",
  62. ]
  63. )
  64. def test_device_class_is_outlet(self):
  65. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  66. def test_sensor_precision(self):
  67. self.assertEqual(self.multiSensor["sensor_current"].native_precision, 0)
  68. self.assertEqual(self.multiSensor["sensor_power"].native_precision, 1)
  69. self.assertEqual(self.multiSensor["sensor_voltage"].native_precision, 1)