diff --git a/ipv6_in_real_life/data_structures.py b/ipv6_in_real_life/data_structures.py index 7bc7887..eabb7b5 100644 --- a/ipv6_in_real_life/data_structures.py +++ b/ipv6_in_real_life/data_structures.py @@ -59,16 +59,20 @@ def as_json(self) -> HostJson: class Entity: country: str category: str + name: str main_host: Host additional_hosts: Sequence[Host] ipv6_ready: Optional[bool] = None @classmethod def from_json(cls, json_entity: Dict[str, Any]) -> "Entity": + main_host = Host(json_entity["main_host"]) + return cls( json_entity["country"], json_entity["category"], - Host(json_entity["main_host"]), + json_entity.get("name", main_host.name), + main_host, tuple(Host(host) for host in json_entity.get("additional_hosts", [])), ) @@ -86,6 +90,7 @@ def as_dict( self, ) -> EntityJson: return { + "name": self.name, "main_host": self.main_host.as_json(), "additional_hosts": [host.as_json() for host in self.additional_hosts], }