Add additional metadata to chargepoints
This commit is contained in:
parent
d25f7f9838
commit
7780f247fb
|
@ -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")
|
||||||
|
|
|
@ -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(),
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue