| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- from homeassistant.components.climate.const import (
- FAN_AUTO,
- FAN_HIGH,
- FAN_LOW,
- FAN_MEDIUM,
- PRESET_COMFORT,
- PRESET_ECO,
- ClimateEntityFeature,
- HVACMode,
- )
- from homeassistant.const import PRECISION_TENTHS, UnitOfTemperature
- from ..const import BECA_BAC002_PAYLOAD
- from ..helpers import assert_device_properties_set
- from ..mixins.climate import TargetTemperatureTests
- from ..mixins.lock import BasicLockTests
- from ..mixins.select import BasicSelectTests
- from .base_device_tests import TuyaDeviceTestCase
- SWITCH_DPS = "1"
- TEMPERATURE_DPS = "2"
- CURRENTTEMP_DPS = "3"
- PROGRAM_DPS = "4"
- PRESET_DPS = "5"
- LOCK_DPS = "6"
- HVACMODE_DPS = "102"
- FAN_DPS = "103"
- class TestBecaBAC002Thermostat(
- BasicLockTests,
- BasicSelectTests,
- TargetTemperatureTests,
- TuyaDeviceTestCase,
- ):
- __test__ = True
- def setUp(self):
- self.setUpForConfig("beca_bac002_thermostat_c.yaml", BECA_BAC002_PAYLOAD)
- self.subject = self.entities.get("climate")
- self.setUpTargetTemperature(
- TEMPERATURE_DPS,
- self.subject,
- min=5.0,
- max=35.0,
- scale=2,
- )
- self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
- self.setUpBasicSelect(
- PROGRAM_DPS,
- self.entities.get("select_schedule"),
- {
- "0": "program",
- "1": "manual",
- },
- )
- self.mark_secondary(["lock_child_lock"])
- def test_supported_features(self):
- self.assertEqual(
- self.subject.supported_features,
- (
- ClimateEntityFeature.FAN_MODE
- | ClimateEntityFeature.PRESET_MODE
- | ClimateEntityFeature.TARGET_TEMPERATURE
- | ClimateEntityFeature.TURN_OFF
- | ClimateEntityFeature.TURN_ON
- ),
- )
- def test_temperature_unit_returns_configured_temperature_unit(self):
- self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
- def test_precision(self):
- self.assertEqual(self.subject.precision, PRECISION_TENTHS)
- async def test_legacy_set_temperature_with_preset_mode(self):
- async with assert_device_properties_set(
- self.subject._device, {PRESET_DPS: True}
- ):
- await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
- async def test_legacy_set_temperature_with_both_properties(self):
- async with assert_device_properties_set(
- self.subject._device,
- {
- TEMPERATURE_DPS: 58,
- PRESET_DPS: False,
- },
- ):
- await self.subject.async_set_temperature(
- temperature=29, preset_mode=PRESET_COMFORT
- )
- def test_current_temperature(self):
- self.dps[CURRENTTEMP_DPS] = 70
- self.assertEqual(self.subject.current_temperature, 35.0)
- def test_hvac_mode(self):
- self.dps[SWITCH_DPS] = True
- self.dps[HVACMODE_DPS] = "0"
- self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
- self.dps[HVACMODE_DPS] = "1"
- self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
- self.dps[HVACMODE_DPS] = "2"
- self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
- self.dps[SWITCH_DPS] = False
- self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
- def test_hvac_modes(self):
- self.assertCountEqual(
- self.subject.hvac_modes,
- [
- HVACMode.COOL,
- HVACMode.FAN_ONLY,
- HVACMode.HEAT,
- HVACMode.OFF,
- ],
- )
- async def test_set_hvac_mode_to_cool(self):
- async with assert_device_properties_set(
- self.subject._device,
- {SWITCH_DPS: True, HVACMODE_DPS: "0"},
- ):
- await self.subject.async_set_hvac_mode(HVACMode.COOL)
- async def test_set_hvac_mode_to_heat(self):
- async with assert_device_properties_set(
- self.subject._device,
- {SWITCH_DPS: True, HVACMODE_DPS: "1"},
- ):
- await self.subject.async_set_hvac_mode(HVACMode.HEAT)
- async def test_set_hvac_mode_to_fan(self):
- async with assert_device_properties_set(
- self.subject._device,
- {SWITCH_DPS: True, HVACMODE_DPS: "2"},
- ):
- await self.subject.async_set_hvac_mode(HVACMode.FAN_ONLY)
- async def test_set_hvac_mode_to_off(self):
- async with assert_device_properties_set(
- self.subject._device, {SWITCH_DPS: False}
- ):
- await self.subject.async_set_hvac_mode(HVACMode.OFF)
- def test_preset_modes(self):
- self.assertCountEqual(self.subject.preset_modes, [PRESET_COMFORT, PRESET_ECO])
- def test_preset_mode(self):
- self.dps[PRESET_DPS] = False
- self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
- self.dps[PRESET_DPS] = True
- self.assertEqual(self.subject.preset_mode, PRESET_ECO)
- async def test_set_preset_to_comfort(self):
- async with assert_device_properties_set(
- self.subject._device,
- {PRESET_DPS: False},
- ):
- await self.subject.async_set_preset_mode(PRESET_COMFORT)
- async def test_set_preset_to_eco(self):
- async with assert_device_properties_set(
- self.subject._device,
- {PRESET_DPS: True},
- ):
- await self.subject.async_set_preset_mode(PRESET_ECO)
- def test_fan_mode(self):
- self.dps[FAN_DPS] = "0"
- self.assertEqual(self.subject.fan_mode, FAN_AUTO)
- self.dps[FAN_DPS] = "1"
- self.assertEqual(self.subject.fan_mode, FAN_HIGH)
- self.dps[FAN_DPS] = "2"
- self.assertEqual(self.subject.fan_mode, FAN_MEDIUM)
- self.dps[FAN_DPS] = "3"
- self.assertEqual(self.subject.fan_mode, FAN_LOW)
- def test_fan_modes(self):
- self.assertCountEqual(
- self.subject.fan_modes,
- [
- FAN_AUTO,
- FAN_LOW,
- FAN_MEDIUM,
- FAN_HIGH,
- ],
- )
- async def test_set_fan_mode_to_auto(self):
- async with assert_device_properties_set(
- self.subject._device,
- {FAN_DPS: "0"},
- ):
- await self.subject.async_set_fan_mode(FAN_AUTO)
- async def test_set_fan_mode_to_high(self):
- async with assert_device_properties_set(
- self.subject._device,
- {FAN_DPS: "1"},
- ):
- await self.subject.async_set_fan_mode(FAN_HIGH)
- async def test_set_fan_mode_to_medium(self):
- async with assert_device_properties_set(
- self.subject._device,
- {FAN_DPS: "2"},
- ):
- await self.subject.async_set_fan_mode(FAN_MEDIUM)
- async def test_set_fan_mode_to_low(self):
- async with assert_device_properties_set(
- self.subject._device,
- {FAN_DPS: "3"},
- ):
- await self.subject.async_set_fan_mode(FAN_LOW)
- def test_extra_state_attribures(self):
- self.assertEqual(self.subject.extra_state_attributes, {})
|