Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to initialize database #661

Closed
pedrocr opened this issue Dec 25, 2024 · 3 comments
Closed

Failure to initialize database #661

pedrocr opened this issue Dec 25, 2024 · 3 comments

Comments

@pedrocr
Copy link

pedrocr commented Dec 25, 2024

I've tried the following example code to try and get events from my network:

#!/usr/bin/env python3
import asyncio

# There are many different radio libraries but they all have the same API
from bellows.zigbee.application import ControllerApplication

class MainListener:
    """
    Contains callbacks that zigpy will call whenever something happens.
    Look for `listener_event` in the Zigpy source or just look at the logged warnings.
    """

    def __init__(self, application):
        self.application = application

    def device_joined(self, device):
        print(f"Device joined: {device}")

    def attribute_updated(self, device, cluster, attribute_id, value):
        print(f"Received an attribute update {attribute_id}={value}"
              f" on cluster {cluster} from device {device}")


async def main():
    app = ControllerApplication(ControllerApplication.SCHEMA({
        "database_path": "./zigbee.db",
        "device": {
            "path": "/dev/ttyUSB0",
        }
    }))

    listener = MainListener(app)
    app.add_listener(listener)

    await app.startup(auto_form=True)

    # Permit joins for a minute
    await app.permit(60)
    await asyncio.sleep(60)

    # Just run forever
    await asyncio.get_running_loop().create_future()

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

This failed with this error:

$ ./zigpy_listener 
Traceback (most recent call last):
  File "./zigpy_listener", line 45, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "./zigpy_listener", line 25, in main
    app = ControllerApplication(ControllerApplication.SCHEMA({
  File "/usr/local/lib/python3.10/dist-packages/bellows/zigbee/application.py", line 84, in __init__
    super().__init__(config)
  File "/usr/local/lib/python3.10/dist-packages/zigpy/application.py", line 70, in __init__
    self._config = self.SCHEMA(config)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 205, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 549, in validate_dict
    return base_validate(path, data.items(), out)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 330, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 779, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 205, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 549, in validate_dict
    return base_validate(path, data.items(), out)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 330, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 590, in validate_sequence
    cval = validate(index_path, value)
  File "/usr/local/lib/python3.10/dist-packages/voluptuous/schema_builder.py", line 779, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.10/dist-packages/zigpy/config/validators.py", line 124, in cv_ota_provider
    provider_type = obj.get(zigpy.config.CONF_OTA_PROVIDER_TYPE)
AttributeError: 'Ledvance' object has no attribute 'get'

I found a similar thing in the zboss library here:

kardia-as/zigpy-zboss#55

So maybe a similar patch is needed to make the database init work:

https://github.com/zigpy/zigpy-znp/pull/250/files

Given that this has happened in multiple places maybe the upstream init function should have this already?

@puddly
Copy link
Contributor

puddly commented Dec 25, 2024

Correct. You need to remove ControllerApplication.SCHEMA from your code.

@pedrocr
Copy link
Author

pedrocr commented Dec 25, 2024

Thanks! That does work. Closing now and here's a minimal example that actually works and receives events:

#!/usr/bin/env python3
import asyncio

# There are many different radio libraries but they all have the same API
from bellows.zigbee.application import ControllerApplication

class MainListener:
    """
    Contains callbacks that zigpy will call whenever something happens.
    Look for `listener_event` in the Zigpy source or just look at the logged warnings.
    """

    def __init__(self, application):
        self.application = application

    def device_joined(self, device):
        print(f"Device joined: {device}")

    def attribute_updated(self, device, cluster, attribute_id, value):
        print(f"Received an attribute update {attribute_id}={value}"
              f" on cluster {cluster} from device {device}")


async def main():
    app = ControllerApplication({
        "database_path": "./zigbee.db",
        "device": {
            "path": "/dev/ttyUSB0",
        }
    })

    listener = MainListener(app)
    app.add_listener(listener)

    await app.startup(auto_form=True)

    # Just run forever
    await asyncio.get_running_loop().create_future()

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

@pedrocr
Copy link
Author

pedrocr commented Dec 25, 2024

Thanks for your help

@pedrocr pedrocr closed this as completed Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants