| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- """Tests for the switch entity."""
- from homeassistant.components.sensor import SensorDeviceClass
- from homeassistant.components.switch import SwitchDeviceClass
- from homeassistant.const import (
- UnitOfElectricCurrent,
- UnitOfElectricPotential,
- UnitOfPower,
- )
- from ..const import KOGAN_SOCKET_PAYLOAD2
- from ..mixins.sensor import MultiSensorTests
- from ..mixins.switch import SwitchableTests
- from .base_device_tests import TuyaDeviceTestCase
- SWITCH_DPS = "1"
- TIMER_DPS = "9"
- CURRENT_DPS = "18"
- POWER_DPS = "19"
- VOLTAGE_DPS = "20"
- class TestSwitchV2(
- MultiSensorTests,
- SwitchableTests,
- TuyaDeviceTestCase,
- ):
- __test__ = True
- def setUp(self):
- self.setUpForConfig("smartplugv2.yaml", KOGAN_SOCKET_PAYLOAD2)
- self.subject = self.entities.get("switch_outlet")
- self.setUpSwitchable(SWITCH_DPS, self.subject)
- self.setUpMultiSensors(
- [
- {
- "name": "sensor_voltage",
- "dps": VOLTAGE_DPS,
- "unit": UnitOfElectricPotential.VOLT,
- "device_class": SensorDeviceClass.VOLTAGE,
- "state_class": "measurement",
- "testdata": (2300, 230.0),
- },
- {
- "name": "sensor_current",
- "dps": CURRENT_DPS,
- "unit": UnitOfElectricCurrent.MILLIAMPERE,
- "device_class": SensorDeviceClass.CURRENT,
- "state_class": "measurement",
- },
- {
- "name": "sensor_power",
- "dps": POWER_DPS,
- "unit": UnitOfPower.WATT,
- "device_class": SensorDeviceClass.POWER,
- "state_class": "measurement",
- "testdata": (1234, 123.4),
- },
- ]
- )
- self.mark_secondary(
- [
- "binary_sensor_problem",
- "sensor_current",
- "sensor_power",
- "sensor_voltage",
- "time_timer",
- ]
- )
- def test_device_class_is_outlet(self):
- self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
- def test_sensor_precision(self):
- self.assertEqual(self.multiSensor["sensor_current"].native_precision, 0)
- self.assertEqual(self.multiSensor["sensor_power"].native_precision, 1)
- self.assertEqual(self.multiSensor["sensor_voltage"].native_precision, 1)
|