Giter VIP home page Giter VIP logo

Comments (15)

kolerak avatar kolerak commented on August 19, 2024

i also wonder if there is a way to look for device state?

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

set_brightness is not found because you are configuring a P110 device.

Change

device = await client.p110("192.168.1.8")

to

device = await client.l510("192.168.1.8")

The lightbulb example contains information about how to get the device info.

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

get_device_info's result will tell you that. It has a device_on property.

from tapo.

kolerak avatar kolerak commented on August 19, 2024

Thank you so much!

from tapo.

kolerak avatar kolerak commented on August 19, 2024

Hi again, thank you so much, i think i kinda figured it out but i am getting this error now:
Serde(Error("missing field type", line: 1, column: 742)) in here device_info = await device.get_device_info()

in this code:

import asyncio
import os
import PySimpleGUI as sg

from tapo import ApiClient


async def main():
  client = ApiClient("xd", "xd")
  device = await client.l510("192.168.1.8")

  device_info = await device.get_device_info()
  layout = [
    [sg.Text("Işık Kontrolcüsü")],
    [
      sg.Button("Aç", key="ON"),
      sg.Button("Kapat", key="OFF"),
      sg.Button("Çıkış"),
    ],
    [sg.Multiline("", size=(40, 10), key="CIHAZ_BILGILERI")],
    [sg.Text("Cihaz Durumu: "), sg.Text("OFF", key="STATUS")],
    [sg.Text("0-100: "), sg.InputText(key="BRIGHTNESS")],
    [sg.Button("Parlaklık Ayarla", key="SET_BRIGHTNESS")],
  ]

  window = sg.Window("Işık", layout)

  while True:
    event, values = window.read()

    # Handle button events
    if event == "ON":
      if device_info.device_on == False:
        await device.on()
        window["CIHAZ_BILGILERI"].update("Device is off. Turning it on...")
        device_info = await device.get_device_info()
      else:
        window["CIHAZ_BILGILERI"].update("Device is already on.")
    elif event == "OFF":
      if device_info.device_on == True:
        await device.off()
        window["CIHAZ_BILGILERI"].update("Device is on. Turning it off...")
        device_info = await device.get_device_info()
      else:
        window["CIHAZ_BILGILERI"].update("Device is already off.")
    elif event == "SET_BRIGHTNESS":
      brightness = int(values["BRIGHTNESS"])
      await device.set_brightness(brightness)
      device_usage = await device.get_device_usage()
      window["CIHAZ_BILGILERI"].update(
        f"Parlaklık ayarlandı, kullanım bilgileri:\n{device_usage.to_dict()}"
      )
    elif event == "Çıkış" or event == sg.WIN_CLOSED:
      break

  window.close()


if __name__ == "__main__":
  asyncio.run(main())

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

What's the device that you're using?
Can you use get_device_info_json instead of get_device_info and paste here the output?

from tapo.

kolerak avatar kolerak commented on August 19, 2024

get_device_info_json this here worked! thanks again the device is l510, I think I should read the source code more :D

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

Can you post the output of get_device_info_json please? I'd like to understand what went from with get_device_info for you.

from tapo.

kolerak avatar kolerak commented on August 19, 2024

yes sure, this is my output for get device info json

{'avatar': 'bulb', 'brightness': 100, 'color_temp_range': [2700, 2700], 'default_states': {'brightness': {'type': 'last_states', 'value': 100}, 're_power_type': 'always_on'}, 'device_id': '', 'device_on': True, 'fw_id': '00000000000000000000000000000000', 'fw_ver': '1.1.0 Build 230721 Rel.224802', 'has_set_location_info': True, 'hw_id': 'FDE1C', 'hw_ver': '2.0', 'ip': '', 'lang': 'tr_TR', 'latitude': 0, 'longitude': 0, 'mac': '00', 'model': 'L510', 'nickname': '', 'oem_id': '', 'overheated': False, 'region': '', 'rssi': -56, 'signal_level': 2, 'specs': '', 'ssid': '', 'time_diff': 180, 'type': 'SMART.TAPOBULB'}

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

Oh wow, the value of default_states is totally different than what I was expecting.
It must be a L510 thing because I couldn't replicate it with L530.

from tapo.

kolerak avatar kolerak commented on August 19, 2024

Wow this is weird then, what are the usual values?

from tapo.

joergsch avatar joergsch commented on August 19, 2024

same issue w/ a newer hardware version (some fields have been redacted)

Object` {"avatar": String("bulb"), "brightness": Number(20), "color_temp_range": Array [Number(2700), Number(2700)], "default_states": Object {"brightness": Object {"type": String("last_states"), "value": Number(20)}, "re_power_type": String("always_on")}, "device_id": String(".........."), "device_on": Bool(true), "fw_id": String("00000000000000000000000000000000"), "fw_ver": String("1.1.2 Build 231120 Rel.201048"), "has_set_location_info": Bool(false), "hw_id": String(".........."), "hw_ver": String("3.0"), "ip": String("10.11.12.13"), "lang": String(""), "latitude": Number(-1879048193), "longitude": Number(-1879048193), "mac": String(".........."), "model": String("L510"), "music_rhythm_enable": Bool(false), "music_rhythm_mode": String("single_lamp"), "nickname": String("QnVsYiBEZXY="), "oem_id": String(".........."), "overheated": Bool(false), "region": String("Europe/Berlin"), "rssi": Number(-50), "signal_level": Number(2), "specs": String(""), "ssid": String(".........."), "time_diff": Number(60), "type": String("SMART.TAPOBULB")}

L610 is behaving the same (json data works, but error "Serde: missing field type at line 1 column 742" if using get_device_info() )

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

Thank you for confirming a second instance.
It must be a change in the L510/L610 API. I was not able to replicate it with L530.

Unfortunately, I do not own a L510 or L610 device.
To apply a fix, I need to know more about all the possible values that default_states could contain.

from tapo.

joergsch avatar joergsch commented on August 19, 2024

the json structure is as following (L510, L610):

"default_states": Object {
    "brightness": Object {
        "type": String(),
        "value": Number(),
    },
    "re_power_type": String(),
},

type: custom, last_states
value: 1..100 (including 100)
re_power_type: always_on, last_states

from tapo.

mihai-dinculescu avatar mihai-dinculescu commented on August 19, 2024

Thank you for the help.
The fix has been released in Tapo Rust v0.7.7 and Tapo Python v0.1.4.

from tapo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.