File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
homeassistant/components/coolmaster
tests/components/coolmaster Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 88from pycoolmasternet_async import SWING_MODES
99
1010from homeassistant .components .climate import (
11+ FAN_AUTO ,
12+ FAN_HIGH ,
13+ FAN_LOW ,
14+ FAN_MEDIUM ,
1115 ClimateEntity ,
1216 ClimateEntityFeature ,
1317 HVACMode ,
3135
3236HA_STATE_TO_CM = {value : key for key , value in CM_TO_HA_STATE .items ()}
3337
34- FAN_MODES = ["low" , "med" , "high" , "auto" ]
38+ CM_TO_HA_FAN = {
39+ "low" : FAN_LOW ,
40+ "med" : FAN_MEDIUM ,
41+ "high" : FAN_HIGH ,
42+ "auto" : FAN_AUTO ,
43+ }
44+
45+ HA_FAN_TO_CM = {value : key for key , value in CM_TO_HA_FAN .items ()}
46+
47+ FAN_MODES = list (CM_TO_HA_FAN .values ())
3548
3649_LOGGER = logging .getLogger (__name__ )
3750
@@ -111,7 +124,7 @@ def hvac_mode(self):
111124 @property
112125 def fan_mode (self ):
113126 """Return the fan setting."""
114- return self ._unit .fan_speed
127+ return CM_TO_HA_FAN [ self ._unit .fan_speed ]
115128
116129 @property
117130 def fan_modes (self ):
@@ -138,7 +151,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
138151 async def async_set_fan_mode (self , fan_mode : str ) -> None :
139152 """Set new fan mode."""
140153 _LOGGER .debug ("Setting fan mode of %s to %s" , self .unique_id , fan_mode )
141- self ._unit = await self ._unit .set_fan_speed (fan_mode )
154+ self ._unit = await self ._unit .set_fan_speed (HA_FAN_TO_CM [ fan_mode ] )
142155 self .async_write_ha_state ()
143156
144157 async def async_set_swing_mode (self , swing_mode : str ) -> None :
Original file line number Diff line number Diff line change @@ -167,23 +167,28 @@ async def test_set_temperature(
167167 assert hass .states .get ("climate.l1_100" ).attributes [ATTR_TEMPERATURE ] == 30
168168
169169
170+ @pytest .mark .parametrize ("target_fan_mode" , FAN_MODES )
170171async def test_set_fan_mode (
171172 hass : HomeAssistant ,
172173 load_int : ConfigEntry ,
174+ target_fan_mode : str ,
173175) -> None :
174176 """Test the Coolmaster climate set fan mode."""
175177 assert hass .states .get ("climate.l1_100" ).attributes [ATTR_FAN_MODE ] == FAN_LOW
178+
176179 await hass .services .async_call (
177180 CLIMATE_DOMAIN ,
178181 SERVICE_SET_FAN_MODE ,
179182 {
180183 ATTR_ENTITY_ID : "climate.l1_100" ,
181- ATTR_FAN_MODE : FAN_HIGH ,
184+ ATTR_FAN_MODE : target_fan_mode ,
182185 },
183186 blocking = True ,
184187 )
185188 await hass .async_block_till_done ()
186- assert hass .states .get ("climate.l1_100" ).attributes [ATTR_FAN_MODE ] == FAN_HIGH
189+ assert (
190+ hass .states .get ("climate.l1_100" ).attributes [ATTR_FAN_MODE ] == target_fan_mode
191+ )
187192
188193
189194async def test_set_swing_mode (
You can’t perform that action at this time.
0 commit comments