From 7780f247fb6519976baa8d9840b59d1f15cb3395 Mon Sep 17 00:00:00 2001 From: BluemediaGER Date: Sun, 14 Apr 2024 17:55:26 +0200 Subject: [PATCH] Add additional metadata to chargepoints --- app/models/chargepoint.py | 5 +++++ app/ocpp_proto/chargepoint.py | 5 ++++- app/schemas/chargepoint.py | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/chargepoint.py b/app/models/chargepoint.py index 3c5db63..417431e 100644 --- a/app/models/chargepoint.py +++ b/app/models/chargepoint.py @@ -11,6 +11,11 @@ class ChargePoint(Base): friendly_name = Column(String, unique=True, index=True) is_active = Column(Boolean, default=True) password = Column(String) + last_seen = Column(DateTime, nullable=True) + vendor_name = Column(String, nullable=True) + model = Column(String, nullable=True) + serial_number = Column(String, nullable=True) + firmware_version = Column(String, nullable=True) connectors = relationship("Connector", cascade="delete, delete-orphan") diff --git a/app/ocpp_proto/chargepoint.py b/app/ocpp_proto/chargepoint.py index f2fb317..7eab494 100644 --- a/app/ocpp_proto/chargepoint.py +++ b/app/ocpp_proto/chargepoint.py @@ -16,10 +16,13 @@ from app.schemas.connector import ConnectorStatus class ChargePoint(cp): @on(Action.BootNotification) - async def on_boot_notification(self, charging_station, reason, **kwargs): + async def on_boot_notification(self, charging_station, **kwargs): with SessionLocal() as db: db_chargepoint = db.query(DbChargePoint).filter(DbChargePoint.friendly_name == self.id).first() db_chargepoint.last_seen = datetime.now(UTC) + for key in charging_station.keys(): + if key in db_chargepoint.__dict__: + setattr(db_chargepoint, key, charging_station[key]) db.commit() return call_result.BootNotificationPayload( current_time=datetime.now(UTC).isoformat(), diff --git a/app/schemas/chargepoint.py b/app/schemas/chargepoint.py index acb30b3..a16db84 100644 --- a/app/schemas/chargepoint.py +++ b/app/schemas/chargepoint.py @@ -19,6 +19,10 @@ class ChargePointCreate(ChargePointBase): class ChargePoint(ChargePointBase): id: UUID last_seen: datetime | None + vendor_name: str | None + model: str | None + serial_number: str | None + firmware_version: str | None connectors: list[Connector] = [] class Config: