Skip to content

Commit

Permalink
use property decorator
Browse files Browse the repository at this point in the history
Use property decorator for API properties, since it saves us a couple of brackets and improves readability.
  • Loading branch information
denpamusic committed Dec 21, 2023
1 parent c824853 commit a0a021d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 9 additions & 4 deletions custom_components/econet300/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def __init__(
self._session = session
self._auth = BasicAuth(username, password)

def host(self):
"""Set host address"""
@property
def host(self) -> str:
"""Get host address"""
return self._host

async def set_param(self, key: str, value: str):
Expand Down Expand Up @@ -127,18 +128,22 @@ async def create(cls, client: EconetClient, cache: MemCache):

return c

def host(self):
@property
def host(self) -> str:
"""Get clients host address"""
return self._client.host()
return self._client.host

@property
def uid(self) -> str:
"""Get uid"""
return self._uid

@property
def sw_rev(self) -> str:
"""Get software version"""
return self._sw_revision

@property
def hw_ver(self) -> str:
"""Get hardware version"""
return self._hw_version
Expand Down
2 changes: 1 addition & 1 deletion custom_components/econet300/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,

try:
api = await make_api(hass, cache, data)
info["uid"] = api.uid()
info["uid"] = api.uid
except AuthError as auth_error:
raise InvalidAuth from auth_error
except TimeoutError as timeout_error:
Expand Down
10 changes: 5 additions & 5 deletions custom_components/econet300/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def has_entity_name(self):
@property
def unique_id(self) -> str | None:
"""Return the unique_id of the entity"""
return f"{self.api.uid()}-{self.entity_description.key}"
return f"{self.api.uid}-{self.entity_description.key}"

@property
def device_info(self) -> DeviceInfo | None:
"""Return device info of the entity"""
return DeviceInfo(
identifiers={(DOMAIN, self.api.uid())},
identifiers={(DOMAIN, self.api.uid)},
name=DEVICE_INFO_CONTROLLER_NAME,
manufacturer=DEVICE_INFO_MANUFACTURER,
model=DEVICE_INFO_MODEL,
configuration_url=self.api.host(),
sw_version=self.api.sw_rev(),
hw_version=self.api.hw_ver(),
configuration_url=self.api.host,
sw_version=self.api.sw_rev,
hw_version=self.api.hw_ver,
)

@callback
Expand Down

0 comments on commit a0a021d

Please sign in to comment.