Skip to content

Commit

Permalink
Merge branch 'release/2023.6.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Jun 8, 2023
2 parents d231dfa + 1360464 commit f115125
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions custom_components/xiaomi_miio_airconditioningcompanion/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def _async_update_power_state(self, state):
if state.state is None:
return
if state.state == STATE_ON:
yield from self.async_turn_on()
await self.async_turn_on()
else:
yield from self.async_turn_off()
await self.async_turn_off()

async def _async_sensor_changed(self, entity_id, old_state, new_state):
"""Handle temperature changes."""
Expand All @@ -307,14 +307,14 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
if new_state is None:
return

yield from self._async_update_power_state(new_state)
await self._async_update_power_state(new_state)

async def _try_command(self, mask_error, func, *args, **kwargs):
"""Call a AC companion command handling error messages."""
from miio import DeviceException

try:
result = yield from self.hass.async_add_job(partial(func, *args, **kwargs))
result = await self.hass.async_add_job(partial(func, *args, **kwargs))

_LOGGER.debug("Response received: %s", result)

Expand All @@ -326,7 +326,7 @@ async def _try_command(self, mask_error, func, *args, **kwargs):

async def async_turn_on(self, speed: str = None, **kwargs) -> None:
"""Turn the miio device on."""
result = yield from self._try_command(
result = await self._try_command(
"Turning the miio device on failed.", self._device.on
)

Expand All @@ -335,7 +335,7 @@ async def async_turn_on(self, speed: str = None, **kwargs) -> None:

async def async_turn_off(self, **kwargs) -> None:
"""Turn the miio device off."""
result = yield from self._try_command(
result = await self._try_command(
"Turning the miio device off failed.", self._device.off
)

Expand All @@ -347,7 +347,7 @@ async def async_update(self):
from miio import DeviceException

try:
state = yield from self.hass.async_add_job(self._device.status)
state = await self.hass.async_add_job(self._device.status)
_LOGGER.debug("Got new state: %s", state)

self._available = True
Expand Down Expand Up @@ -473,36 +473,36 @@ async def async_set_temperature(self, **kwargs):
if kwargs.get(ATTR_HVAC_MODE) is not None:
self._hvac_mode = OperationMode(kwargs.get(ATTR_HVAC_MODE))

yield from self._send_configuration()
await self._send_configuration()

async def async_set_swing_mode(self, swing_mode):
"""Set the swing mode."""
from miio.airconditioningcompanion import SwingMode

self._swing_mode = SwingMode[swing_mode.title()]
yield from self._send_configuration()
await self._send_configuration()

async def async_set_fan_mode(self, fan_mode):
"""Set the fan mode."""
from miio.airconditioningcompanion import FanSpeed

self._fan_mode = FanSpeed[fan_mode.title()]
yield from self._send_configuration()
await self._send_configuration()

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
if hvac_mode == OperationMode.Off.value:
result = yield from self._try_command(
result = await self._try_command(
"Turning the miio device off failed.", self._device.off
)
if result:
self._state = False
self._hvac_mode = HVAC_MODE_OFF
yield from self._send_configuration()
await self._send_configuration()
else:
self._hvac_mode = OperationMode(hvac_mode).value
self._state = True
yield from self._send_configuration()
await self._send_configuration()

@property
def swing_mode(self):
Expand All @@ -522,7 +522,7 @@ async def _send_configuration(self):
from miio.airconditioningcompanion import Power

if self._air_condition_model is not None:
yield from self._try_command(
await self._try_command(
"Sending new air conditioner configuration failed.",
self._device.send_configuration,
self._air_condition_model,
Expand All @@ -543,12 +543,12 @@ async def _send_configuration(self):

async def async_learn_command(self, slot, timeout):
"""Learn a infrared command."""
yield from self.hass.async_add_job(self._device.learn, slot)
await self.hass.async_add_job(self._device.learn, slot)

_LOGGER.info("Press the key you want Home Assistant to learn")
start_time = utcnow()
while (utcnow() - start_time) < timedelta(seconds=timeout):
message = yield from self.hass.async_add_job(self._device.learn_result)
message = await self.hass.async_add_job(self._device.learn_result)
# FIXME: Improve python-miio here?
message = message[0]
_LOGGER.debug("Message received from device: '%s'", message)
Expand All @@ -558,12 +558,12 @@ async def async_learn_command(self, slot, timeout):
self.hass.components.persistent_notification.async_create(
log_msg, title="Xiaomi Miio Remote"
)
yield from self.hass.async_add_job(self._device.learn_stop, slot)
await self.hass.async_add_job(self._device.learn_stop, slot)
return

yield from asyncio.sleep(1)
await asyncio.sleep(1)

yield from self.hass.async_add_job(self._device.learn_stop, slot)
await self.hass.async_add_job(self._device.learn_stop, slot)
_LOGGER.error("Timeout. No infrared command captured")
self.hass.components.persistent_notification.async_create(
"Timeout. No infrared command captured", title="Xiaomi Miio Remote"
Expand All @@ -579,15 +579,15 @@ async def async_send_command(self, command, **kwargs):
time.sleep(delay)

if command.startswith("01"):
yield from self._try_command(
await self._try_command(
"Sending new air conditioner configuration failed.",
self._device.send_command,
command,
)
elif command.startswith("FE"):
if self._air_condition_model is not None:
# Learned infrared commands has the prefix 'FE'
yield from self._try_command(
await self._try_command(
"Sending custom infrared command failed.",
self._device.send_ir_code,
self._air_condition_model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"construct==2.10.56",
"python-miio>=0.5.12"
],
"version": "2023.6.0.1"
"version": "2023.6.0.2"
}

0 comments on commit f115125

Please sign in to comment.