11# type: ignore[attr-defined]
22"""wearables in development"""
3-
4- import importlib
5- import importlib .util
6- from importlib import import_module
3+ import os
74
85try :
96 from importlib import metadata as importlib_metadata
107except ImportError : # for Python<3.8
118 import importlib_metadata as importlib_metadata
129
13- from .constants import *
14- from .devices import *
10+ from .devices import registry
1511
1612
1713def get_device (device_name , ** kwargs ):
@@ -34,56 +30,22 @@ def get_device(device_name, **kwargs):
3430 device = wearipedia.get_device("whoop/whoop_4")
3531 ...
3632 """
37- company , model = device_name .split ("/" )
38-
39- module_path = f"{ PACKAGE_PATH } /devices/{ device_name } .py"
40-
41- spec = importlib .util .spec_from_file_location (
42- name = f"wearipedia.devices.{ company } .{ model } " ,
43- location = module_path ,
44- )
45-
46- module = importlib .util .module_from_spec (spec )
47-
48- spec .loader .exec_module (module )
49-
50- class_name = getattr (module , "class_name" )
33+ try :
34+ device_class = registry .get_device_class (device_name )
35+ except KeyError :
36+ raise ValueError (f"Device '{ device_name } ' is not registered" )
5137
52- return getattr ( module , class_name ) (** kwargs )
38+ return device_class (** kwargs )
5339
5440
55- def get_all_device_names ():
41+ def get_all_device_names () -> list [ str ] :
5642 """Get a list of all device names.
5743
5844 :return: a list of device names
5945 :rtype: List
6046 """
6147
62- return [
63- "apple/healthkit" ,
64- "biostrap/evo" ,
65- "cronometer/cronometer" ,
66- "whoop/whoop_4" ,
67- "withings/scanwatch" ,
68- "withings/bodyplus" ,
69- "withings/sleepmat" ,
70- "dreem/headband_2" ,
71- "dexcom/pro_cgm" ,
72- "garmin/fenix_7s" ,
73- "google/googlefit" ,
74- "polar/h10" ,
75- "polar/verity_sense" ,
76- "nutrisense/cgm" ,
77- "fitbit/fitbit_charge_4" ,
78- "fitbit/fitbit_charge_6" ,
79- "fitbit/fitbit_sense" ,
80- "oura/oura_ring3" ,
81- "coros/coros_pace_2" ,
82- "polar/vantage" ,
83- "strava/strava" ,
84- "myfitnesspal/myfitnesspal" ,
85- "qualtrics/qualtrics" ,
86- ]
48+ return registry .REGISTRY .keys ()
8749
8850
8951def get_version () -> str :
0 commit comments