test_smartplugv2.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. def setUp(self):
  24. self.setUpForConfig("smartplugv2.yaml", KOGAN_SOCKET_PAYLOAD2)
  25. self.subject = self.entities.get("switch_outlet")
  26. self.setUpSwitchable(SWITCH_DPS, self.subject)
  27. self.setUpMultiSensors(
  28. [
  29. {
  30. "name": "sensor_voltage",
  31. "dps": VOLTAGE_DPS,
  32. "unit": UnitOfElectricPotential.VOLT,
  33. "device_class": SensorDeviceClass.VOLTAGE,
  34. "state_class": "measurement",
  35. "testdata": (2300, 230.0),
  36. },
  37. {
  38. "name": "sensor_current",
  39. "dps": CURRENT_DPS,
  40. "unit": UnitOfElectricCurrent.MILLIAMPERE,
  41. "device_class": SensorDeviceClass.CURRENT,
  42. "state_class": "measurement",
  43. },
  44. {
  45. "name": "sensor_power",
  46. "dps": POWER_DPS,
  47. "unit": UnitOfPower.WATT,
  48. "device_class": SensorDeviceClass.POWER,
  49. "state_class": "measurement",
  50. "testdata": (1234, 123.4),
  51. },
  52. ]
  53. )
  54. self.mark_secondary(
  55. [
  56. "binary_sensor_problem",
  57. "sensor_current",
  58. "sensor_power",
  59. "sensor_voltage",
  60. "time_timer",
  61. ]
  62. )
  63. def test_device_class_is_outlet(self):
  64. self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
  65. def test_sensor_precision(self):
  66. self.assertEqual(self.multiSensor["sensor_current"].native_precision, 0)
  67. self.assertEqual(self.multiSensor["sensor_power"].native_precision, 1)
  68. self.assertEqual(self.multiSensor["sensor_voltage"].native_precision, 1)