You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Hubitat Maker API"""importosfromdotenvimportload_dotenvimporthubitatcontrol.genericasgenericimporthubitatcontrol.lightsaslightsimporthubitatcontrol.sensorsassensorsfromhubitatcontrol.hubimportHubclassGetSingleDevice:
def__init__(self, hub_in: Hub):
""" Used to get a single device based on lookup """self.hub=hub_indefname(self, device_name: str):
""" Get a device by name and cast to the matched spec """foriinself.hub.devices:
ifi["name"] ==device_name:
returnDeviceInit(device_in=i, hub_in=self.hub).cast_device()
defid(self, device_id: int):
""" Get a device by id and cast to the matched spec """foriinself.hub.devices:
ifi["id"] ==str(device_id):
returnDeviceInit(device_in=i, hub_in=self.hub).cast_device()
classGetDevices:
def__init__(self, hub_in: Hub):
""" Get a list of pre-casted devices you can search though """self.hub=hub_indef__get_devices_from_capabilities__(self, capabilities_list: [str]):
device_list= []
foriinself.hub.devices:
ifall([xini["capabilities"] forxincapabilities_list]):
d=DeviceInit(self.hub, i).cast_device()
device_list.append(d)
returndevice_listdefTemperatureSensor(self) ->list[sensors.TemperatureSensor]:
# TODO -> Fix temp data get from EcoBee <-returnself.__get_devices_from_capabilities__(sensors.TemperatureSensor.spec)
defEnvironmentalSensor(self) ->list[sensors.EnvironmentalSensor]:
returnself.__get_devices_from_capabilities__(sensors.EnvironmentalSensor.spec)
defSwitch(self) ->list[generic.Switch]:
returnself.__get_devices_from_capabilities__(generic.Switch.spec)
defOutlet(self) ->list[generic.ZigbeeOutlet]:
returnself.__get_devices_from_capabilities__(generic.ZigbeeOutlet.spec)
defDimmer(self) ->list[lights.Dimmer]:
returnself.__get_devices_from_capabilities__(lights.Dimmer.spec)
defBulb(self) ->list[lights.Bulb]:
returnself.__get_devices_from_capabilities__(lights.Bulb.spec)
defColorTempBulb(self) ->list[lights.ColorTempBulb]:
returnself.__get_devices_from_capabilities__(lights.ColorTempBulb.spec)
defRGBWBulb(self) ->list[lights.RGBWBulb]:
returnself.__get_devices_from_capabilities__(lights.RGBWBulb.spec)
classDeviceInit:
def__init__(self, hub_in: Hub, device_in: generic.Device):
""" This class is normally not used, as it's for dynamically casting devices """self.hub=hub_inself.device=device_indefcast_device(self):
"""The order here is very important that we cast the device properly based on increasing complexity / functionality"""c=self.device["capabilities"]
ifall([xincforxinsensors.TemperatureSensor.spec]):
returnsensors.TemperatureSensor(self.hub, self.device)
ifall([xincforxinsensors.EnvironmentalSensor.spec]):
returnsensors.EnvironmentalSensor(self.hub, self.device)
ifall([xincforxingeneric.ZigbeeOutlet.spec]):
returngeneric.ZigbeeOutlet(self.hub, self.device)
ifall([xincforxinlights.RGBWBulb.spec]):
returnlights.RGBWBulb(self.hub, self.device)
ifall([xincforxinlights.ColorTempBulb.spec]):
returnlights.ColorTempBulb(self.hub, self.device)
ifall([xincforxinlights.Dimmer.spec]):
returnlights.Dimmer(self.hub, self.device)
ifall([xincforxinlights.Bulb.spec]):
returnlights.Bulb(self.hub, self.device)
ifall([xincforxinlights.Switch.spec]):
returnlights.Switch(self.hub, self.device)
defget_hub_envs() ->Hub:
""" Generates a Hub object from local environmental variables """load_dotenv()
host_env=os.getenv("HUBITAT_HOST")
token_env=os.getenv("HUBITAT_API_TOKEN")
app_id_env=os.getenv("HUBITAT_API_APP_ID")
cloud_token=os.getenv("HUBITAT_CLOUD_TOKEN")
returnHub(host=host_env, token=token_env, app_id=app_id_env, cloud_token=cloud_token)
The text was updated successfully, but these errors were encountered:
https://api.github.com/Jelloeater/hubitatcontrol/blob/6cfe8757bff19d70f85d6342551e00d9181dab8d/hubitatcontrol/__init__.py#L52
The text was updated successfully, but these errors were encountered: