def main(): mothership_url = birdhouse_utils.make_mothership_url(args, config) tbapi = TbApi(mothership_url, thingsboard_username, thingsboard_password) print(f"Retrieving template dashboard {template_dash}... ", end='', flush=True) template_dash_def = tbapi.get_dashboard_definition( tbapi.get_dashboard_by_name(template_dash)) # We also need the id of the device being swapped out template_device_id = tbapi.get_id( tbapi.get_device_by_name( birdhouse_utils.make_device_name(args["<device>"]))) print(" done.") all_devices = tbapi.get_devices_by_name(copy_to_pattern) for device in all_devices: num = birdhouse_utils.get_device_number_from_name(device["name"]) print(f"Updating dashboard for {device['name']}") dash_name_being_replaced = birdhouse_utils.make_dash_name(num) device_name = birdhouse_utils.make_device_name(num) device = tbapi.get_device_by_name(device_name) device_id = tbapi.get_id(device) # The dash we are replacing: dash_being_replaced = tbapi.get_dashboard_by_name( dash_name_being_replaced) dash_id_being_replaced = tbapi.get_id(dash_being_replaced) dash_def = tbapi.get_dashboard_definition( tbapi.get_dashboard_by_name( template_dash)) # dash_def will be modified birdhouse_utils.reassign_dash_to_new_device(dash_def, dash_name_being_replaced, template_device_id, device_id, device_name) dash_def["id"]["id"] = dash_id_being_replaced # del_humidity(dash_def) # exit() tbapi.save_dashboard(dash_def)
def main(): tbapi = TbApi(motherShipUrl, username, password) devices = tbapi.get_devices_by_name("Birdhouse") print(devices) for d in devices: print(d["name"]) exit() # Lookup missing fields, such as zip, lat, and lon birdhouse_utils.update_customer_data(cust_info) if cust_info["lat"] is None or cust_info["lon"] is None: print("Must have valid lat/lon to continue!") exit(1) name = birdhouse_utils.make_device_name(birdhouse_number) cust = tbapi.get_customer(name) devices = tbapi.get_customer_devices(cust) print(devices) device = tbapi.get_device_by_name(name) customer = tbapi.update_customer(cust, None, cust_info["address"], cust_info["address2"], cust_info["city"], cust_info["state"], cust_info["zip"], cust_info["country"]) server_attributes = { "latitude": cust_info["lat"], "longitude": cust_info["lon"], "address": birdhouse_utils.one_line_address(cust_info) } tbapi.set_server_attributes(device, server_attributes) exit() cust = tbapi.get_customer(name)