| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- """Tests for Parkside PLGS 2012 A1 Smart Charger"""
- from homeassistant.components.binary_sensor import BinarySensorDeviceClass
- from homeassistant.components.number.const import NumberDeviceClass
- from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
- from homeassistant.const import (
- PERCENTAGE,
- UnitOfElectricCurrent,
- UnitOfElectricPotential,
- UnitOfTemperature,
- UnitOfTime,
- )
- from ..const import PARKSIDE_PLGS2012A1_PAYLOAD
- from ..mixins.binary_sensor import MultiBinarySensorTests
- from ..mixins.number import MultiNumberTests
- from ..mixins.select import BasicSelectTests
- from ..mixins.sensor import MultiSensorTests
- from ..mixins.switch import MultiSwitchTests
- from .base_device_tests import TuyaDeviceTestCase
- SWITCH_DPS = "1"
- NAME_DPS = "2"
- CURRENT_DPS = "3"
- VOLTAGE_DPS = "4"
- BATTERY_DPS = "5"
- TEMPERATURE_DPS = "6"
- MODE_DPS = "7"
- STORAGE_DPS = "8"
- LIMITER_DPS = "9"
- MAXTEMPCOUNT_DPS = "10"
- FAULT_DPS = "11"
- MAXCURRENT_DPS = "101"
- REMAIN_DPS = "102"
- ALMOSTCHARGED_DPS = "103"
- FULLYCHARGED_DPS = "104"
- class TestParksidePLGS2012A1Charger(
- MultiBinarySensorTests,
- MultiNumberTests,
- BasicSelectTests,
- MultiSensorTests,
- MultiSwitchTests,
- TuyaDeviceTestCase,
- ):
- __test__ = True
- def setUp(self):
- self.setUpForConfig(
- "parkside_plgs2012a1_smart_charger.yaml", PARKSIDE_PLGS2012A1_PAYLOAD
- )
- self.setUpMultiBinarySensors(
- [
- {
- "name": "binary_sensor_almost_charged",
- "dps": ALMOSTCHARGED_DPS,
- },
- {
- "name": "binary_sensor_fully_charged",
- "dps": FULLYCHARGED_DPS,
- },
- {
- "name": "binary_sensor_problem",
- "dps": FAULT_DPS,
- "device_class": BinarySensorDeviceClass.PROBLEM,
- "testdata": (32, 0),
- },
- ],
- )
- self.setUpMultiNumber(
- [
- {
- "name": "number_charge_current",
- "dps": CURRENT_DPS,
- "device_class": NumberDeviceClass.CURRENT,
- "max": 30.000,
- "step": 0.1,
- "scale": 1000,
- "unit": UnitOfElectricCurrent.AMPERE,
- },
- {
- "name": "number_charge_voltage",
- "dps": VOLTAGE_DPS,
- "device_class": NumberDeviceClass.VOLTAGE,
- "max": 25.0,
- "scale": 1000,
- "step": 0.1,
- "unit": UnitOfElectricPotential.VOLT,
- },
- ],
- )
- self.setUpBasicSelect(
- MODE_DPS,
- self.entities.get("select_charge_type"),
- {
- "ECO": "Eco",
- "quick": "Performance",
- "standard": "Balanced",
- "individual": "Expert",
- },
- )
- self.setUpMultiSensors(
- [
- {
- "name": "sensor_battery",
- "dps": BATTERY_DPS,
- "unit": PERCENTAGE,
- "device_class": SensorDeviceClass.BATTERY,
- },
- {
- "name": "sensor_time_remaining",
- "dps": REMAIN_DPS,
- "unit": UnitOfTime.MINUTES,
- "device_class": SensorDeviceClass.DURATION,
- },
- {
- "name": "sensor_temperature",
- "dps": TEMPERATURE_DPS,
- "unit": UnitOfTemperature.CELSIUS,
- "device_class": SensorDeviceClass.TEMPERATURE,
- "state_class": SensorStateClass.MEASUREMENT,
- },
- {
- "name": "sensor_max_current",
- "dps": MAXCURRENT_DPS,
- "unit": UnitOfElectricCurrent.AMPERE,
- "device_class": SensorDeviceClass.CURRENT,
- "testdata": (1234, 1.234),
- },
- {
- "name": "sensor_max_temperature_count",
- "dps": MAXTEMPCOUNT_DPS,
- },
- ],
- )
- self.setUpMultiSwitch(
- [
- {
- "name": "switch",
- "dps": SWITCH_DPS,
- },
- {
- "name": "switch_storage",
- "dps": STORAGE_DPS,
- },
- {
- "name": "switch_temperature_limiter",
- "dps": LIMITER_DPS,
- },
- ],
- )
- self.mark_secondary(
- [
- "number_charge_current",
- "number_charge_voltage",
- "switch_storage",
- "switch_temperature_limiter",
- "sensor_temperature",
- "sensor_max_temperature_count",
- "select_charge_type",
- "sensor_max_current",
- "binary_sensor_almost_charged",
- "binary_sensor_fully_charged",
- "binary_sensor_problem",
- ]
- )
- def test_multi_switch_state_attributes(self):
- switch = self.multiSwitch.get("switch")
- storage = self.multiSwitch.get("switch_storage")
- temp = self.multiSwitch.get("switch_temperature_limiter")
- self.assertEqual(storage.extra_state_attributes, {})
- self.assertEqual(temp.extra_state_attributes, {})
- self.dps[NAME_DPS] = "test"
- self.assertDictEqual(switch.extra_state_attributes, {"model": "test"})
- def test_multi_bsensor_extra_state_attributes(self):
- self.dps[FAULT_DPS] = 2
- problem = self.multiBSensor.get("binary_sensor_problem")
- almost = self.multiBSensor.get("binary_sensor_almost_charged")
- fully = self.multiBSensor.get("binary_sensor_fully_charged")
- self.assertEqual(almost.extra_state_attributes, {})
- self.assertEqual(fully.extra_state_attributes, {})
- self.assertCountEqual(problem.extra_state_attributes, {"fault_code": 2})
|