Closed leonhard-s closed 3 years ago
(Continuing here to keep it with the issue itself)
@LordFlashmeow Feel free to take this one, it has been bugging me for a while too. I originally pushed this back because I was already working on moving to pydantic for the rest of the object model at the time and wanted to figure that out first.
Here are some thoughts I've written down for myself, for inspiration:
events.py
is already quite cluttered; the subclasses should therefore be part of the models
sub module, same as the other object model data classes.Event
must inherit from pydantic.BaseModel
(or Ps2Data
, that way we also keep the immutability), with all other events inheriting from ittype
class attribute that points back to its enum equivalent (I want to keep the enums around for simplicity)events
module is fine imoTrigger
and related classes be extended to accept Event
sub classes in place of EventType
enums?When implementing the MetagameEvent
sub class, be wary of the zone_id
field; it does not actually get sent with payloads anymore.
We can handle this in two ways: Either we don't include it at all and instead add a zone_id
property that returns the appropriate value as per the reference in the Wiki, or we make it an optional field that defaults to -1
, then add a pydantic validator that performs the same lookup and replacement if the value hasn't been changed. This also allows new alerts to just work in case the field ever gets fixed.
So yeah - if you want to help with this one, I'd appreciate it 👍
Gonna try my hand at implementing the above; I don't want to have to write the event handler docs twice. :D
Added in a24a7f08
Nice, that's simpler than what I did. I'll make a draft pr so you can see what I was thinking.
Currently, there is a single
Event
class representing any payloads returned by the websocket API.It would be beneficial to return a custom data class for each of the ~20 event types. I do not want to replace the
EventType
enum values as listing the subclasses defined for a given base is more hassle than just looking at the enum values.