GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Issue printing device in on_discovered: pydantic.error_wrappers.ValidationError: 3 validation errors for SmartBulbPreset · Issue #439 · python-kasa/python-kasa

Issue printing device in on_discovered: pydantic.error_wrappers.ValidationError: 3 validation errors for SmartBulbPreset #439

New issue
Copy link
New issue
Copy link
Closed
#440
Closed
Issue printing device in on_discovered: pydantic.error_wrappers.ValidationError: 3 validation errors for SmartBulbPreset#439
#440
Copy link
Labels
bugSomething isn't workingSomething isn't working

Description

@jimboca
jimboca
opened on Mar 16, 2023
Issue body actions

My code is printing a device in the method called by on_discovered:
await Discover.discover(target=broadcast_address,on_discovered=self.discover_new_add_device)

Which fails with:

Traceback (most recent call last):
  File "/var/polyglot/pg3/ns/000db952c414_2/nodes/Controller.py", line 157, in discover_new_add_device
    LOGGER.debug(f'enter: mac={smac} dev={dev}')
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartdevice.py", line 706, in __repr__
    return f"<{self._device_type} model {self.model} at {self.host} ({self.alias}), is_on: {self.is_on} - dev specific: {self.state_information}>"
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartdevice.py", line 88, in wrapped
    return f(*args, **kwargs)
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartlightstrip.py", line 82, in state_information
    info = super().state_information
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartdevice.py", line 88, in wrapped
    return f(*args, **kwargs)
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartbulb.py", line 468, in state_information
    info["Presets"] = self.presets
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartdevice.py", line 88, in wrapped
    return f(*args, **kwargs)
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartbulb.py", line 512, in presets
    return [SmartBulbPreset(**vals) for vals in self.sys_info["preferred_state"]]
  File "/var/polyglot/.local/lib/python3.9/site-packages/kasa/smartbulb.py", line 512, in <listcomp>
    return [SmartBulbPreset(**vals) for vals in self.sys_info["preferred_state"]]
  File "/var/polyglot/.local/lib/python3.9/site-packages/pydantic/main.py", line 342, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 3 validation errors for SmartBulbPreset
hue
  field required (type=value_error.missing)
saturation
  field required (type=value_error.missing)
color_temp
  field required (type=value_error.missing)

Activity

  1. rytilahti commented on Mar 16, 2023

    @rytilahti
    rytilahti
    on Mar 16, 2023
    Member
    More actions

    Could you enable debug logging and retry to see what are the contents for the presets (keyed preferred_state)? The preset parsing was created using my color test bulb and I suppose yours doesn't support colors, so we need to adjust those fields.

    Which device is that btw? Would you mind adding a fixture to https://github.com/python-kasa/python-kasa/tree/master/kasa/tests/fixtures as all currently known devices do have those fields? You can find the dump_devinfo.py script inside devtools directory that will create the file.

  2. rytilahti
    added
    bugSomething isn't workingSomething isn't working
    on Mar 16, 2023
  3. jimboca commented on Mar 16, 2023

    @jimboca
    jimboca
    on Mar 16, 2023
    ContributorAuthor
    More actions

    I will do that tonight when I am back home.

    Reacted by Teemu R.
  4. jimboca commented on Mar 18, 2023

    @jimboca
    jimboca
    on Mar 18, 2023
    ContributorAuthor
    More actions

    I've not been able to get debug info out, will look into that more, but this is one of the devices causing an issue:
    dev=<DeviceType.Plug model HS100(US) at 192.168.86.11 (Home Development Env HS100), is_on: True - dev specific: {'LED state': True, 'On since': datetime.datetime(2023, 3, 15, 4, 37, 52)}>
    Never mind, still looking...

  5. jimboca commented on Mar 18, 2023

    @jimboca
    jimboca
    on Mar 18, 2023
    ContributorAuthor
    More actions

    I'm trying to run pytest on the device but it doesn't work as documented?

    (python-kasa-py3.9) [admin@polisy-dev ~/dev/pg3/python-kasa]$ pytest --ip  192.168.86.177
    ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
    pytest: error: unrecognized arguments: --ip
      inifile: /usr/home/admin/dev/pg3/python-kasa/pyproject.toml
      rootdir: /usr/home/admin/dev/pg3/python-kasa
    ``
    I've never used poetry before so probably something I did wrong?
    
  6. rytilahti commented on Mar 19, 2023

    @rytilahti
    rytilahti
    on Mar 19, 2023
    Member
    More actions

    Could you please try the dump_devinfo.py script I mentioned in my previous comment? That will perform some queries on the device and create a JSON file containing the responses (sensitive information is redacted from the output).

    I haven't run the test suite against a real device for a while, as it's not usually that useful, but pytest kasa --ip=192.168.86.177 should run the tests against the a device. Running those tests against a real device is not recommended though, as they will perform state changes on the device (turning off and on, changing their settings, etc).

    But there's something odd going on, as a HS100 plug as shown by your output should not really try to access bulb-specific presets... I don't currently have any bulbs but the on_discovered seems to be working fine on other devices:

    import asyncio
    from kasa import Discover
    
    broadcast_address = "xx.xx.xx.255"
    
    async def discovered(dev):
        print(f"discovered {dev}")
    
    async def main():
        await Discover.discover(target=broadcast_address, on_discovered=discovered)
    
    
    if __name__ == "__main__":
        asyncio.run(main())
    
    discovered <DeviceType.Plug model KP115(EU) at xx.xx.xx.xx (TP-LINK_Smart Plug_2FBC), is_on: True - dev specific: {'LED state': False, 'On since': datetime.datetime(2023, 3, 3, 14, 39, 15)}>
    discovered <DeviceType.Plug model HS110(EU) at xx.xx.xx.xx (Bedroom), is_on: True - dev specific: {'LED state': False, 'On since': datetime.datetime(2023, 3, 3, 14, 49, 15)}>
    discovered <DeviceType.Strip model KP303(UK) at xx.xx.xx.xx (kp303), is_on: False - dev specific: {'LED state': False, 'Childs count': 0, 'On since': None}>
    discovered <DeviceType.Plug model KP115(EU) at xx.xx.xx.xx (livingroom), is_on: True - dev specific: {'LED state': False, 'On since': datetime.datetime(2023, 3, 3, 14, 40, 44)}>
    discovered <DeviceType.Plug model HS110(EU) at xx.xx.xx.xx (new alias), is_on: False - dev specific: {'LED state': False, 'On since': None}>
    
  7. jimboca commented on Mar 19, 2023

    @jimboca
    jimboca
    on Mar 19, 2023
    ContributorAuthor
    More actions

    Looks like it's an issue with my KL430, I'll add the device info file, but here's the log:

    Testing Call(module='system', method='get_sysinfo')..OK
    Testing Call(module='emeter', method='get_realtime')..FAIL module not support
    Testing Call(module='smartlife.iot.dimmer', method='get_dimmer_parameters')..FAIL module not support
    Testing Call(module='smartlife.iot.common.emeter', method='get_realtime')..OK
    Testing Call(module='smartlife.iot.smartbulb.lightingservice', method='get_light_state')..FAIL module not support
    Testing Call(module='smartlife.iot.LAS', method='get_config')..FAIL module not support
    Testing Call(module='smartlife.iot.PIR', method='get_config')..FAIL module not support
    Got 2 successes
    ## device info file ##
    
  8. jimboca
    added a commit that references this issue on Mar 19, 2023

    Add some of my device fixtures, KL430 is for python-kasa#439

    385eb64
  9. jimboca commented on Mar 30, 2023

    @jimboca
    jimboca
    on Mar 30, 2023
    ContributorAuthor
    More actions

    Hi @rytilahti are you able to debug & fix with my PR #441 ?

  10. rytilahti commented on Mar 30, 2023

    @rytilahti
    rytilahti
    on Mar 30, 2023
    Member
    More actions

    Hey @jimboca, that helps indeed! Looks like the presets that activate an effect have different contents. I just updated the PR accordingly, feel free to test and report back if you wish :-)

    Reacted by Jimbo.Automates
  11. jimboca commented on Mar 30, 2023

    @jimboca
    jimboca
    on Mar 30, 2023
    ContributorAuthor
    More actions

    I'm running with your change, no errors seen, will check again tonight to make sure it's all working properly.

  12. rytilahti commented on Mar 30, 2023

    @rytilahti
    rytilahti
    on Mar 30, 2023
    Member
    More actions

    Great, there should be no issues while reading and I'll add some tests later to make sure the save_preset functionality does not break either.

  13. jimboca commented on Apr 1, 2023

    @jimboca
    jimboca
    on Apr 1, 2023
    ContributorAuthor
    More actions

    No issues after running with it for a couple days now.

    Reacted by Teemu R.
  14. rytilahti
    closed this as completedin #440on Apr 1, 2023
  15. rytilahti
    added a commit that references this issue on Jun 3, 2024

    Add some of my device fixtures, KL430 is for #439

    81610a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.