Add additional metadata to chargepoints

This commit is contained in:
Oliver Traber 2024-04-14 17:55:26 +02:00
parent d25f7f9838
commit 7780f247fb
Signed by: Bluemedia
GPG key ID: C0674B105057136C
3 changed files with 13 additions and 1 deletions

View file

@ -11,6 +11,11 @@ class ChargePoint(Base):
friendly_name = Column(String, unique=True, index=True) friendly_name = Column(String, unique=True, index=True)
is_active = Column(Boolean, default=True) is_active = Column(Boolean, default=True)
password = Column(String) password = Column(String)
last_seen = Column(DateTime, nullable=True) 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") connectors = relationship("Connector", cascade="delete, delete-orphan")

View file

@ -16,10 +16,13 @@ from app.schemas.connector import ConnectorStatus
class ChargePoint(cp): class ChargePoint(cp):
@on(Action.BootNotification) @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: with SessionLocal() as db:
db_chargepoint = db.query(DbChargePoint).filter(DbChargePoint.friendly_name == self.id).first() db_chargepoint = db.query(DbChargePoint).filter(DbChargePoint.friendly_name == self.id).first()
db_chargepoint.last_seen = datetime.now(UTC) 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() db.commit()
return call_result.BootNotificationPayload( return call_result.BootNotificationPayload(
current_time=datetime.now(UTC).isoformat(), current_time=datetime.now(UTC).isoformat(),

View file

@ -19,6 +19,10 @@ class ChargePointCreate(ChargePointBase):
class ChargePoint(ChargePointBase): class ChargePoint(ChargePointBase):
id: UUID id: UUID
last_seen: datetime | None last_seen: datetime | None
vendor_name: str | None
model: str | None
serial_number: str | None
firmware_version: str | None
connectors: list[Connector] = [] connectors: list[Connector] = []
class Config: class Config: