Exemple #1
0
    def __init__(self, client, device):
        """initialize a LGE Washer Device."""
        LGEDevice.__init__(self, client, device)

        import wideq
        self._washer = wideq.WasherDevice(client, device)

        self._washer.monitor_start()
        self._washer.monitor_start()
        self._washer.delete_permission()
        self._washer.delete_permission()

        # The response from the monitoring query.
        self._state = None

        self.update()
Exemple #2
0
def mon(client, device_id):
    """Monitor any device, displaying generic information about its
    status.
    """
    #State
    #Remain_Time_H
    #Remain_Time_M
    #Initial_Time_H
    #Initial_Time_M
    #Course
    #Error
    #Soil
    #SpinSpeed
    #WaterTemp
    #RinseOption
    #DryLevel
    #Reserve_Time_H
    #Reserve_Time_M
    #Option1
    #Option2
    #Option3
    #PreState
    #SmartCourse
    #TCLCount
    #LoadItem
    #CourseType
    #Standby

    mclient = mqtt.Client()
    mclient.on_connect = on_connect
    mclient.on_message = on_message

    mclient.connect(MQTT_HOST, MQTT_PORT, 60)

    device = client.get_device(device_id)
    model = client.model_info(device)

    if device.type == wideq.DeviceType.WASHER:
        print('Attempting to poll washer.')
        washer = wideq.WasherDevice(client, device)
        try:
            washer.monitor_start()
        except wideq.core.NotConnectedError:
            print('Device not available.')
            return

        try:
            while True:
                time.sleep(1)
                state = washer.poll()
                if state:
                    json_data = client.dump()
                    for key in state.keys():
                        jsonpath_expression = parse('$.model_info..Value.' +
                                                    key + '.option."' +
                                                    state[key] + '"')
                        match = jsonpath_expression.find(json_data)
                        if (match):
                            if (key == 'SpinSpeed' or key == 'RinseOption'
                                    or key == 'Soil' or key == 'WaterTemp'):
                                output_value = re.sub("@WM_[A-Z]+_[A-Z]+_", "",
                                                      match[0].value).replace(
                                                          "_W", "").replace(
                                                              "_",
                                                              " ").title()
                            else:
                                output_value = re.sub(
                                    "@WM_[A-Z]+_", "", match[0].value).replace(
                                        "_W", "").replace("_", " ").title()
                            state[key] = output_value
                    mclient.publish("stat/washer", str(state))
                    break
        except KeyboardInterrupt:
            pass
        finally:
            washer.monitor_stop()
            mclient.disconnect()