Skip to content

Commit

Permalink
Use async client
Browse files Browse the repository at this point in the history
  • Loading branch information
jvitkauskas committed Dec 20, 2023
1 parent ae09716 commit 2cf8b3f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion custom_components/blauberg_s21/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

try:
client = S21Client(host, port)
client.poll()
await client.poll()
except Exception as ex:
raise ConfigEntryNotReady(
"Failed to connect to modbusTCP://%s:%d", host, port
Expand Down
18 changes: 10 additions & 8 deletions custom_components/blauberg_s21/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def sw_version(self) -> Optional[str]:
@property
def icon(self) -> Optional[str]:
if self._client.device:
if not self._client.device.available:
return "mdi:lan-disconnect"
if self._client.device.is_boosting:
return "mdi:fan-plus"
if self._client.device.hvac_action == BlS21HVACAction.OFF:
Expand All @@ -199,10 +201,10 @@ def icon(self) -> Optional[str]:
return "mdi:fan"
return "mdi:fan"

def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
self._client.set_hvac_mode(HA_TO_S21_HVACMODE[hvac_mode])
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
await self._client.set_hvac_mode(HA_TO_S21_HVACMODE[hvac_mode])

def set_fan_mode(self, fan_mode: str) -> None:
async def async_set_fan_mode(self, fan_mode: str) -> None:
int_fan_mode = (
255
if fan_mode == "custom"
Expand All @@ -214,12 +216,12 @@ def set_fan_mode(self, fan_mode: str) -> None:
if fan_mode == FAN_HIGH
else int(fan_mode)
)
self._client.set_fan_mode(int_fan_mode)
await self._client.set_fan_mode(int_fan_mode)

def set_temperature(self, **kwargs: Any) -> None:
async def async_set_temperature(self, **kwargs: Any) -> None:
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is not None:
self._client.set_temperature(int(temperature))
await self._client.set_temperature(int(temperature))

def update(self) -> None:
self._client.poll()
async def async_update(self) -> None:
await self._client.poll()
2 changes: 1 addition & 1 deletion custom_components/blauberg_s21/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
host = data[CONF_HOST]
port = data[CONF_PORT]
client = S21Client(host, port)
client.poll()
await client.poll()
except UnsupportedDeviceException:
raise
except Exception as exception:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/blauberg_s21/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"integration_type": "device",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/jvitkauskas/homeassistant_blauberg_s21/issues",
"requirements": ["pybls21==3.0.4"],
"version": "0.1.3"
"requirements": ["pybls21==4.0.0"],
"version": "0.2.0"
}

0 comments on commit 2cf8b3f

Please sign in to comment.