Skip to content

Commit 5be642a

Browse files
committed
Bump aiohttp to 3.7.4, small typing improvements
1 parent 7fc4fa3 commit 5be642a

5 files changed

Lines changed: 22 additions & 19 deletions

File tree

crownstone_cloud/cloud_models/crownstones.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,26 @@ async def async_update_crownstone_data(self) -> None:
6262
for crownstone_id in removed_items:
6363
del self.crownstones[crownstone_id]
6464

65-
def find(self, crownstone_name: str) -> object or None:
65+
def find(self, crownstone_name: str) -> "Crownstone" or None:
6666
"""Search for a crownstone by name and return crownstone object if found."""
6767
for crownstone in self.crownstones.values():
6868
if crownstone_name == crownstone.name:
6969
return crownstone
70+
71+
return None
7072

71-
def find_by_id(self, crownstone_id) -> object or None:
73+
def find_by_id(self, crownstone_id) -> "Crownstone" or None:
7274
"""Search for a crownstone by id and return crownstone object if found."""
73-
return self.crownstones[crownstone_id]
75+
return self.crownstones.get(crownstone_id)
7476

75-
def find_by_uid(self, crownstone_uid) -> object or None:
77+
def find_by_uid(self, crownstone_uid) -> "Crownstone" or None:
7678
"""Search for a crownstone by uid and return crownstone object if found."""
7779
for crownstone in self.crownstones.values():
7880
if crownstone_uid == crownstone.unique_id:
7981
return crownstone
8082

83+
return None
84+
8185

8286
class CrownstoneAbility:
8387
"""Represents a Crownstone Ability"""
@@ -112,10 +116,9 @@ def __init__(self, cloud, data: Dict[str, Any]) -> None:
112116
self.cloud = cloud
113117
self.data: Dict[str, Any] = data
114118
self.abilities: Dict[str, CrownstoneAbility] = {}
115-
# power usage (W)
119+
# Not cloud data, store your own data here (from Crownstone USB)
116120
self.power_usage = 0
117-
# energy usage (Joule)
118-
self.energy_usage = None
121+
self.energy_usage = 0
119122

120123
@property
121124
def name(self) -> str:

crownstone_cloud/cloud_models/locations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ async def async_update_location_presence(self) -> None:
7070
if present_location == location.cloud_id:
7171
location.present_people.append(presence['userId'])
7272

73-
def find(self, location_name: str) -> object or None:
73+
def find(self, location_name: str) -> "Location" or None:
7474
"""Search for a sphere by name and return sphere object if found."""
7575
for location in self.locations.values():
7676
if location_name == location.name:
7777
return location
7878

7979
return None
8080

81-
def find_by_id(self, location_id: str) -> object or None:
81+
def find_by_id(self, location_id: str) -> "Location" or None:
8282
"""Search for a sphere by id and return sphere object if found."""
83-
return self.locations[location_id]
83+
return self.locations.get(location_id)
8484

8585

8686
class Location:

crownstone_cloud/cloud_models/spheres.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ async def async_update_sphere_data(self) -> None:
5454
for sphere_id in removed_items:
5555
del self.spheres[sphere_id]
5656

57-
def find(self, sphere_name: str) -> object or None:
57+
def find(self, sphere_name: str) -> "Sphere" or None:
5858
"""Search for a sphere by name and return sphere object if found."""
5959
for sphere in self.spheres.values():
6060
if sphere_name == sphere.name:
6161
return sphere
6262

6363
return None
6464

65-
def find_by_id(self, sphere_id: str) -> object or None:
65+
def find_by_id(self, sphere_id: str) -> "Sphere" or None:
6666
"""Search for a sphere by id and return sphere object if found."""
67-
return self.spheres[sphere_id]
67+
return self.spheres.get(sphere_id)
6868

6969

7070
class Sphere:

crownstone_cloud/cloud_models/users.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""User handler for Crownstone cloud data."""
2-
from typing import Dict, Any
2+
from typing import Dict, Any, List
33

44

55
class Users:
@@ -52,7 +52,7 @@ async def async_update_user_data(self) -> None:
5252
for user_id in removed_items:
5353
del self.users[user_id]
5454

55-
def find_by_first_name(self, first_name: str) -> list:
55+
def find_by_first_name(self, first_name: str) -> List["User"] or List:
5656
"""Search for a user by first name and return a list with the users found."""
5757
found_users = []
5858
for user in self.users.values():
@@ -61,7 +61,7 @@ def find_by_first_name(self, first_name: str) -> list:
6161

6262
return found_users
6363

64-
def find_by_last_name(self, last_name: str) -> list:
64+
def find_by_last_name(self, last_name: str) -> List["User"] or List:
6565
"""Search for a user by last name and return a list with the users found."""
6666
found_users = []
6767
for user in self.users.values():
@@ -70,9 +70,9 @@ def find_by_last_name(self, last_name: str) -> list:
7070

7171
return found_users
7272

73-
def find_by_id(self, user_id: str) -> object or None:
73+
def find_by_id(self, user_id: str) -> "User" or None:
7474
"""Search for a user by id and return crownstone object if found."""
75-
return self.users[user_id]
75+
return self.users.get(user_id)
7676

7777

7878
class User:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
aiohttp>=3.6.2
1+
aiohttp>=3.7.4
22
asynctest>=0.13.0
33
codecov>=2.1.10
44
certifi

0 commit comments

Comments
 (0)