Esempio n. 1
0
async def _scan_network_for_devices(hass, call):
    import homeassistant.components.ais_device_search_mqtt.sensor as dsm

    global GLOBAL_X
    my_ip = ais_global.get_my_global_ip()
    info = ""
    if GLOBAL_X == 0:
        GLOBAL_X += 1
        # clear the value
        dsm.MQTT_DEVICES = []
        dsm.NET_DEVICES = []
        dsm.DOM_DEVICES = []
        hass.states.async_set(
            "sensor.network_devices_info_value",
            "",
            {"text": "wykrywam, to może potrwać minutę..."},
        )

        # send the message to all robots in network
        await hass.services.async_call(
            "mqtt", "publish", {"topic": "cmnd/dom/status", "payload": 0}
        )
        # fix for new robots, Tasmota 6.4.0
        await hass.services.async_call(
            "mqtt", "publish", {"topic": "dom/cmnd/status", "payload": 0}
        )
        # disco
        await hass.services.async_call(
            "mqtt", "publish", {"topic": "dom/cmnd/SetOption19", "payload": 1}
        )

        await hass.services.async_call("ais_shell_command", "scan_network_for_devices")
    # 256
    elif 0 < GLOBAL_X < 256:
        GLOBAL_X += 1
        rest_url = "http://{}.{}/cm?cmnd=status"
        url = rest_url.format(my_ip.rsplit(".", 1)[0], str(GLOBAL_X))
        info = "Sprawdzam " + my_ip.rsplit(".", 1)[0]
        info += "." + str(GLOBAL_X) + "\n"
        info += dsm.get_text()
        hass.states.async_set("sensor.network_devices_info_value", "", {"text": info})

        # search android devices
        rest_url_a = "http://{}.{}:8122"
        url_a = rest_url_a.format(my_ip.rsplit(".", 1)[0], str(GLOBAL_X))

        await hass.services.async_call(
            "ais_shell_command", "scan_device", {"url": url, "url_a": url_a}
        )

    else:
        GLOBAL_X = 0
        hass.states.async_set(
            "sensor.network_devices_info_value", "", {"text": dsm.get_text()}
        )
        await hass.services.async_call(
            "ais_ai_service", "say_it", {"text": dsm.get_text_to_say()}
        )
Esempio n. 2
0
 def bg_cb_a(resp, *args, **kwargs):
     try:
         # parse the json storing the result on the response object
         json_ws_resp = resp.json()
         model = json_ws_resp["Model"]
         manufacturer = json_ws_resp["Manufacturer"]
         ip = json_ws_resp["IPAddressIPv4"]
         mac = json_ws_resp["MacWlan0"]
         dsm.DOM_DEVICES.append("- " + model + " " + manufacturer +
                                ", http://" + ip + ":8180")
         info = dsm.get_text()
         hass.states.async_set("sensor.network_devices_info_value", "",
                               {"text": info})
         # add the device to the speakers lists
         hass.async_add_job(
             hass.services.async_call(
                 "ais_cloud",
                 "get_players",
                 {
                     "device_name":
                     model + " " + manufacturer + "(" + ip + ")",
                     CONF_IP_ADDRESS: ip,
                     CONF_MAC: mac,
                 },
             ))
     except Exception:
         pass
Esempio n. 3
0
 def bg_cb(resp, *args, **kwargs):
     try:
         # parse the json storing the result on the response object
         json_ws_resp = resp.json()
         hostname = urlparse(resp.url).hostname
         name = json_ws_resp["Status"]["FriendlyName"][0]
         # ip = json_ws_resp["StatusNET"]["IPAddress"]
         dsm.NET_DEVICES.append("- " + name + ", http://" + hostname)
         info = dsm.get_text()
         hass.states.async_set("sensor.network_devices_info_value", "",
                               {"text": info})
     except Exception:
         pass
Esempio n. 4
0
async def _show_network_devices_info(hass, call):
    import homeassistant.components.ais_device_search_mqtt.sensor as dsm

    info = dsm.get_text()
    hass.states.async_set("sensor.network_devices_info_value", "ok",
                          {"text": info})