1+ from typing import Dict
12from typing import List
23from typing import Optional
34
@@ -12,21 +13,21 @@ class ShellHubDeviceInfo:
1213 arch : str
1314 platform : str
1415
15- def __init__ (self , device_info_json : dict ):
16+ def __init__ (self , device_info_json : Dict [ str , str ] ):
1617 self .id = device_info_json ["id" ]
1718 self .pretty_name = device_info_json ["pretty_name" ]
1819 self .version = device_info_json ["version" ]
1920 self .arch = device_info_json ["arch" ]
2021 self .platform = device_info_json ["platform" ]
2122
22- def __repr__ (self ):
23+ def __repr__ (self ) -> str :
2324 return (
2425 f"ShellHubDeviceInfo(id={ self .id } , pretty_name={ self .pretty_name } , "
2526 f"version={ self .version } , arch={ self .arch } , platform={ self .platform } )"
2627 )
2728
28- def __str__ (self ):
29- return self .__repr__ ()
29+ def __str__ (self ) -> str :
30+ return self .pretty_name
3031
3132
3233class ShellHubDevice :
@@ -46,7 +47,7 @@ class ShellHubDevice:
4647 tags : List [str ]
4748 acceptable : bool
4849
49- def __init__ (self , api_object : shellhub .models .base .ShellHub , device_json : dict ):
50+ def __init__ (self , api_object : shellhub .models .base .ShellHub , device_json ): # type: ignore
5051 self ._api = api_object
5152
5253 self .uid = device_json ["uid" ]
@@ -68,16 +69,17 @@ def __init__(self, api_object: shellhub.models.base.ShellHub, device_json: dict)
6869 self .tags = device_json ["tags" ]
6970 self .acceptable = device_json ["acceptable" ]
7071
71- def delete (self ):
72+ def delete (self ) -> bool :
7273 response = self ._api .make_request (endpoint = f"/api/devices/{ self .uid } " , method = "DELETE" )
7374 if response .status_code == 200 :
7475 return True
7576 elif response .status_code == 404 :
7677 raise ShellHubApiError (f"Device { self .uid } not found." )
7778 else :
7879 response .raise_for_status ()
80+ return False
7981
80- def rename (self , name : Optional [str ] = None ):
82+ def rename (self , name : Optional [str ] = None ) -> bool :
8183 """
8284 Set a new name for the device. If no name is provided, the name will be the mac address of the device
8385 """
@@ -93,8 +95,9 @@ def rename(self, name: Optional[str] = None):
9395 raise ShellHubApiError (f"Device with name { name } already exists." )
9496 else :
9597 response .raise_for_status ()
98+ return False
9699
97- def accept (self ):
100+ def accept (self ) -> bool :
98101 if not self .acceptable :
99102 raise ShellHubApiError (f"Device { self .uid } is not acceptable." )
100103
@@ -106,19 +109,20 @@ def accept(self):
106109 raise ShellHubApiError (f"Device { self .uid } not found." )
107110 else :
108111 response .raise_for_status ()
112+ return False
109113
110- def refresh (self ):
114+ def refresh (self ) -> None :
111115 response = self ._api .make_request (endpoint = f"/api/devices/{ self .uid } " , method = "GET" )
112116 if response .status_code == 404 :
113117 raise ShellHubApiError (f"Device { self .uid } not found." )
114118 elif response .status_code != 200 :
115119 response .raise_for_status ()
116- self .__init__ (self ._api , response .json ())
120+ self .__init__ (self ._api , response .json ()) # type: ignore
117121
118- def __repr__ (self ):
122+ def __repr__ (self ) -> str :
119123 return (
120124 f"ShellHubDevice(name={ self .name } , online={ self .online } , namespace={ self .namespace } , status={ self .status } )"
121125 )
122126
123- def __str__ (self ):
127+ def __str__ (self ) -> str :
124128 return self .uid
0 commit comments