gilesknap / maaspower

Provide MAAS power control via webhooks for various remote control power switches.
Apache License 2.0
18 stars 13 forks source link

MaasConfig and find_device #10

Closed gilesknap closed 2 years ago

gilesknap commented 2 years ago

This is a pedantic issue to make the code look neater.

_devices cannot be declared in the dataclass MaasConfig or it corrupts the schema - hence all the lint ignore directives in function find_device.

Possible solutions:

gilesknap commented 2 years ago

Resolved.

By declaring _devices as a Classvar

_devices: ClassVar[Dict[str, SwitchDevice]] = {}

We avoid it being in the schema.

This makes MaasConfig a singleton which is OK for our use of it. But not ideal since there is no checks on this and the tests will create multiple instances.