Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from bestlibre/asyncio
Browse files Browse the repository at this point in the history
Compatibility with asyncio version of cozytouchpy
  • Loading branch information
cyr-ius authored May 20, 2020
2 parents e93e4ca + b61b7ee commit 9a80a21
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 46 deletions.
4 changes: 2 additions & 2 deletions custom_components/cozytouch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ async def async_connect(hass, parameters):
parameters[CONF_PASSWORD],
parameters[CONF_TIMEOUT],
)
await hass.async_add_executor_job(cozytouch.connect)
return await hass.async_add_executor_job(cozytouch.get_setup)
await cozytouch.connect()
return await cozytouch.get_setup()
except AuthentificationFailed as e:
raise AuthentificationFailed(e)
except CozytouchException as e:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/cozytouch/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def async_update(self):
"""Fetch new state data for this sensor."""
_LOGGER.debug("Update binary sensor {name}".format(name=self.name))
try:
await self.hass.async_add_executor_job(self.sensor.update)
await self.sensor.update()
except CozytouchException:
_LOGGER.error("Device data no retrieve {}".format(self.name))

Expand Down
40 changes: 11 additions & 29 deletions custom_components/cozytouch/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,67 +151,49 @@ def preset_modes(self):

async def async_turn_away_mode_on(self):
"""Turn away on."""
await self.hass.async_add_executor_job(self.heater.turn_away_mode_on)
await self.heater.turn_away_mode_on()

async def async_turn_away_mode_off(self):
"""Turn away off."""
await self.hass.async_add_executor_job(self.heater.turn_away_mode_off)
await self.heater.turn_away_mode_off()

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
if const.ATTR_TARGET_TEMP_HIGH in kwargs:
await self.hass.async_add_executor_job(
self.heater.set_comfort_temperature, kwargs[const.ATTR_TARGET_TEMP_HIGH]
)
await self.heater.set_comfort_temperature(kwargs[const.ATTR_TARGET_TEMP_HIGH])
_LOGGER.info(
"Set HIGH TEMP to {temp}".format(
temp=kwargs[const.ATTR_TARGET_TEMP_HIGH]
)
)
if const.ATTR_TARGET_TEMP_LOW in kwargs:
await self.hass.async_add_executor_job(
self.heater.set_eco_temperature, kwargs[const.ATTR_TARGET_TEMP_LOW]
)
await self.heater.set_eco_temperature(kwargs[const.ATTR_TARGET_TEMP_LOW])
_LOGGER.info(
"Set LOW TEMP to {temp}".format(temp=kwargs[const.ATTR_TARGET_TEMP_LOW])
)

async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set new target hvac mode. HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF."""
if hvac_mode == const.HVAC_MODE_OFF:
await self.hass.async_add_executor_job(
self.heater.set_operating_mode, OperatingModeState.STANDBY
)
await self.heater.set_operating_mode(OperatingModeState.STANDBY)
elif hvac_mode == const.HVAC_MODE_HEAT:
await self.hass.async_add_executor_job(
self.heater.set_operating_mode, OperatingModeState.BASIC
)
await self.heater.set_operating_mode(OperatingModeState.BASIC)
elif hvac_mode == const.HVAC_MODE_AUTO:
await self.hass.async_add_executor_job(
self.heater.set_operating_mode, OperatingModeState.INTERNAL
)
await self.heater.set_operating_mode(OperatingModeState.INTERNAL)

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode. PRESET_ECO, PRESET_COMFORT."""
if preset_mode == const.PRESET_SLEEP:
await self.hass.async_add_executor_job(
self.heater.set_targeting_heating_level,
TargetingHeatingLevelState.FROST_PROTECTION,
)
await self.heater.set_targeting_heating_level(TargetingHeatingLevelState.FROST_PROTECTION)
elif preset_mode == const.PRESET_ECO:
await self.hass.async_add_executor_job(
self.heater.set_targeting_heating_level, TargetingHeatingLevelState.ECO
)
await self.heater.set_targeting_heating_level(TargetingHeatingLevelState.ECO)
elif preset_mode == const.PRESET_COMFORT:
await self.hass.async_add_executor_job(
self.heater.set_targeting_heating_level,
TargetingHeatingLevelState.COMFORT,
)
await self.heater.set_targeting_heating_level(TargetingHeatingLevelState.COMFORT)

async def async_update(self):
"""Fetch new state data for this sensor."""
_LOGGER.debug("Update thermostat {name}".format(name=self.name))
try:
await self.hass.async_add_executor_job(self.heater.update)
await self.heater.update()
except CozytouchException:
_LOGGER.error("Device data no retrieve {}".format(self.name))
4 changes: 2 additions & 2 deletions custom_components/cozytouch/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def async_update(self):
"""Fetch new state data for this sensor."""
_LOGGER.debug("Update sensor {name}".format(name=self.name))
try:
await self.hass.async_add_executor_job(self.sensor.update)
await self.sensor.update()
except CozytouchException:
_LOGGER.error("Device data no retrieve {}".format(self.name))

Expand Down Expand Up @@ -121,7 +121,7 @@ def unit_of_measurement(self):
async def async_update(self):
"""Fetch new state data for this sensor."""
_LOGGER.debug("Update sensor {name}".format(name=self.name))
await self.hass.async_add_executor_job(self.sensor.update)
await self.sensor.update()

@property
def device_info(self):
Expand Down
6 changes: 3 additions & 3 deletions custom_components/cozytouch/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ def device_class(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn the entity on."""
await self.hass.async_add_executor_job(self.heater.turn_on)
await self.heater.turn_on()

async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
await self.hass.async_add_executor_job(self.heater.turn_off)
await self.heater.turn_off()

async def async_update(self):
"""Fetch new state data for this heater."""
_LOGGER.debug("Update switch {name}".format(name=self.name))
try:
await self.hass.async_add_executor_job(self.heater.update)
await self.heater.update()
except CozytouchException:
_LOGGER.error("Device data no retrieve {}".format(self.name))

Expand Down
14 changes: 5 additions & 9 deletions custom_components/cozytouch/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,22 @@ def is_boost_mode_on(self):

async def async_set_operation_mode(self, operation_mode):
"""Set new target operation mode."""
await self.hass.async_add_executor_job(
self.water_heater.set_operating_mode, HASS_TO_COZY_STATE[operation_mode]
)
await self.water_heater.set_operating_mode(HASS_TO_COZY_STATE[operation_mode])

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
self._target_temperature = kwargs.get(ATTR_TEMPERATURE)
await self.hass.async_add_executor_job(
self.water_heater.set_temperature, self._target_temperature
)
await self.water_heater.set_temperature(self._target_temperature)

async def async_set_away_mode(self, period):
"""Turn away on."""
_LOGGER.debug("Set away mode for {} days".format(period))
await self.hass.async_add_executor_job(self.water_heater.set_away_mode, period)
await self.water_heater.set_away_mode(period)

async def async_set_boost_mode(self, period):
"""Turn away on."""
_LOGGER.debug("Set boost mode for {} days".format(period))
await self.hass.async_add_executor_job(self.water_heater.set_boost_mode, period)
await self.water_heater.set_boost_mode(period)

async def async_turn_boost_mode_off(self):
"""Turn away off."""
Expand All @@ -227,7 +223,7 @@ async def async_update(self):
"""Fetch new state data for this sensor."""
_LOGGER.debug("Update water heater {name}".format(name=self.name))
try:
await self.hass.async_add_executor_job(self.water_heater.update)
await self.water_heater.update()
except CozytouchException:
_LOGGER.error("Device data no retrieve {}".format(self.name))

Expand Down

0 comments on commit 9a80a21

Please sign in to comment.