Пример #1
0
def main():
    tbapi = TbApi(motherShipUrl, username, password)

    # 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)
Пример #2
0
def main():
    cleanup = True

    tbapi = TbApi(motherShipUrl, username, password)

    # Get a definition of our template dashboard
    template_dash = tbapi.get_dashboard_by_name(dashboard_template_name)
    dash_def = tbapi.get_dashboard_definition(tbapi.get_id(template_dash))

    # Lookup missing fields, such as zip, lat, and lon
    update_customer_data()

    if cust_lat is None or cust_lon is None:
        print("Must have valid lat/lon in order to add device!")
        exit(1)

    # Create new customer and device records on the server
    customer = tbapi.add_customer(cust_name, cust_address, cust_address2,
                                  cust_city, cust_state, cust_zip,
                                  cust_country, cust_email, cust_phone)

    server_attributes = {"latitude": cust_lat, "longitude": cust_lon}

    shared_attributes = {"LED": "Unknown", "nonce": 0}
    device = tbapi.add_device(make_device_name(cust_name), sensor_type,
                              shared_attributes, server_attributes)
    device_id = tbapi.get_id(device)

    # We need to store the device token as a server attribute so our REST services can get access to it
    device_token = tbapi.get_device_token(device_id)

    server_attributes = {"device_token": device_token}

    tbapi.set_server_attributes(device_id, server_attributes)

    # Upate the dash def. to point at the device we just created (modifies dash_def)
    update_dash_def(dash_def, cust_name, device_id)

    # Create a new dash with our definition, and assign it to the new customer
    dash = tbapi.create_dashboard_for_customer(cust_name + ' Dash', dash_def)
    tbapi.assign_dash_to_user(tbapi.get_id(dash), tbapi.get_id(customer))

    if cleanup:
        # input("Press Enter to continue...")   # Don't run from Sublime with this line enabled!!!

        print("Cleaning up!")
        tbapi.delete_dashboard(tbapi.get_id(dash))
        tbapi.delete_device(device_id)
        tbapi.delete_customer_by_id(tbapi.get_id(customer))