Skip to content

Commit

Permalink
Fixed compatibility with homeassistant >= 2021.5
Browse files Browse the repository at this point in the history
  • Loading branch information
corvis committed Jul 6, 2021
1 parent fcc23a8 commit eeb5f3b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ dmypy.json
# Pyre type checker
.pyre/

.idea
.idea/
22 changes: 11 additions & 11 deletions custom_components/prana/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from homeassistant.components.fan import FanEntity, SUPPORT_SET_SPEED
from homeassistant.core import callback
from homeassistant.helpers.device_registry import IDX_IDENTIFIERS
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from prana_rc.contrib.api import PranaStateDTO
Expand Down Expand Up @@ -59,12 +59,12 @@ class BasePranaEntity(CoordinatorEntity):
"""Parent class for Prana entities"""

def __init__(
self,
coordinator: DataUpdateCoordinator,
api_client: PranaRCAsyncClient,
device_config: dict,
base_entity_id: str,
base_entity_name: str,
self,
coordinator: DataUpdateCoordinator,
api_client: PranaRCAsyncClient,
device_config: dict,
base_entity_id: str,
base_entity_name: str,
):
super().__init__(coordinator)
self.coordinator = coordinator
Expand All @@ -82,12 +82,12 @@ def device_address(self):
return self._device_config[const.OPT_DEVICE_ADDRESS]

@property
def device_info(self) -> Optional[Dict[str, Any]]:
return {
IDX_IDENTIFIERS: {(const.DOMAIN, self.unique_id)},
def device_info(self) -> DeviceInfo:
return DeviceInfo({
'identifiers': {(const.DOMAIN, self.unique_id)},
const.ATTR_DEVICE_ADDRESS: self._device_config.get(const.OPT_DEVICE_ADDRESS),
const.ATTR_DEVICE_NAME: self._device_config.get(const.OPT_DEVICE_NAME),
}
})

@property
def assumed_state(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions custom_components/prana/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"domain": "prana",
"name": "Prana Recuperators",
"documentation": "",
"version": "0.2.0",
"dependencies": [],
"codeowners": [
"@corvis"
Expand Down
25 changes: 25 additions & 0 deletions tmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from os import listdir
from os.path import isfile, isdir, getsize, join


def get_dir_size(path: str) -> int:
if isfile(path):
return getsize(path)
else:
size = 0
for file_name in listdir(path):
p = join(path, file_name)
if isfile(p):
size += getsize(p)
elif isdir(p):
size += get_dir_size(p)
else:
pass # Skip everything else
return size

getsize('/tmp/.X11-unix')
print(get_dir_size('/home/corvis/Documents'))

# Questions -> Exceptions what are the cases?
# IsFile -> What if it's not a file and not dir (links, block devices, sockets)?
# Recursion depth

0 comments on commit eeb5f3b

Please sign in to comment.