Skip to content

Commit

Permalink
Ruff formatting #68
Browse files Browse the repository at this point in the history
  • Loading branch information
rstrouse committed Jul 6, 2024
1 parent 14e3e3e commit dddb35d
Show file tree
Hide file tree
Showing 12 changed files with 926 additions and 643 deletions.
21 changes: 3 additions & 18 deletions custom_components/espsomfy_rts/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ def _handle_coordinator_update(self) -> None:
and self._controller.data["shadeId"] == self._shade_id
and self._controller.data["event"] == EVT_SHADESTATE
and "flags" in self._controller.data
):
if self._attr_is_on != bool(
(int(self._controller.data["flags"]) & 0x20) == 0x20
):
self._attr_is_on = bool(
(int(self._controller.data["flags"]) & 0x20) == 0x20
)
self.async_write_ha_state()
elif (
) or (
self._sensor_type == "group"
and "groupId" in self._controller.data
and self._controller.data["groupId"] == self._group_id
Expand Down Expand Up @@ -174,15 +166,7 @@ def _handle_coordinator_update(self) -> None:
and self._controller.data["shadeId"] == self._shade_id
and self._controller.data["event"] == EVT_SHADESTATE
and "flags" in self._controller.data
):
if self._attr_is_on != bool(
(int(self._controller.data["flags"]) & 0x10) == 0x10
):
self._attr_is_on = bool(
(int(self._controller.data["flags"]) & 0x10) == 0x10
)
self.async_write_ha_state()
elif (
) or (
self._sensor_type == "group"
and "groupId" in self._controller.data
and self._controller.data["groupId"] == self._group_id
Expand All @@ -199,6 +183,7 @@ def _handle_coordinator_update(self) -> None:

@property
def icon(self) -> str:
"""The icon for the entity."""
if self.is_on:
return "mdi:wind-power"
return "mdi:wind-power-outline"
Expand Down
15 changes: 8 additions & 7 deletions custom_components/espsomfy_rts/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def __init__(
self._attr_icon = cfg.icon
self._available = True
self._action = cfg.action

self._attr_assumed_state = True
self._attr_supported_features = cfg.features

super().__init__(controller=controller, data=None)

async def async_press(self) -> None:
Expand All @@ -135,12 +136,12 @@ async def async_press(self) -> None:

def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
if (
self._controller.data["event"] == EVT_CONNECTED
and "connected" in self._controller.data
):
self._available = bool(self._controller.data["connected"])
self.async_write_ha_state()
if self._controller.data.get("event", "") == EVT_CONNECTED:
if "connected" in self._controller.data and self._attr_available != bool(
self._controller.data["connected"]
):
self._attr_available = bool(self._controller.data["connected"])
self.async_write_ha_state()

@property
def available(self) -> bool:
Expand Down
12 changes: 4 additions & 8 deletions custom_components/espsomfy_rts/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@


async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
"""Validate the user input allows us to connect.
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
"""
"""Validate the user input allows us to connect."""

session = aiohttp_client.async_get_clientsession(hass)
async with session.get(f'http://{data["host"]}/discovery') as resp:
Expand Down Expand Up @@ -98,10 +96,8 @@ async def async_step_user(
if user_input is not None:
try:
if not is_host_valid(user_input.get(CONF_HOST, "")):
raise InvalidHost()
else:
self.host = user_input.get(CONF_HOST, "")

raise InvalidHost
self.host = user_input.get(CONF_HOST, "")
api = ESPSomfyAPI(self.hass, 0, user_input)
await api.discover()
await self.async_set_unique_id(f"espsomfy_{api.server_id}")
Expand Down Expand Up @@ -210,7 +206,7 @@ async def async_step_init(
if user_input is not None:
try:
if not is_host_valid(user_input[CONF_HOST]):
raise InvalidHost()
raise InvalidHost
api = ESPSomfyAPI(self.hass, 0, user_input)
await api.discover()
await api.login(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/espsomfy_rts/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from homeassistant.const import Platform

VERSION = "v2.4.5"
VERSION = "v2.4.6"
DOMAIN = "espsomfy_rts"
MANUFACTURER = "rstrouse"
API_CONTROLLER = "/controller"
Expand Down
Loading

0 comments on commit dddb35d

Please sign in to comment.