Skip to content

Commit

Permalink
use model_dump as dict is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jun 26, 2024
1 parent 966f28d commit 9745df9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
16 changes: 8 additions & 8 deletions chargeamps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def command_list_chargepoints(
) -> None:
res = []
for cp in await client.get_chargepoints():
res.append(cp.to_dict())
res.append(cp.model_dump(by_alias=True))
print(json.dumps(res, indent=4))


Expand All @@ -45,9 +45,9 @@ async def command_get_chargepoint_status(
if args.connector_id:
for c in cp.connector_statuses:
if c.connector_id == args.connector_id:
print(json.dumps(c.to_dict(), indent=4))
print(json.dumps(c.model_dump(by_alias=True), indent=4))
else:
print(json.dumps(cp.to_dict(), indent=4))
print(json.dumps(cp.model_dump(by_alias=True), indent=4))


async def command_get_chargepoint_sessions(
Expand All @@ -68,7 +68,7 @@ async def command_get_chargepoint_sessions(
charge_point_id, start_time, end_time
):
if args.connector_id is None or args.connector_id == session.connector_id:
res.append(session.to_dict())
res.append(session.model_dump(by_alias=True))
res = sorted(res, key=lambda i: i["id"])
print(json.dumps(res, indent=4))

Expand All @@ -78,7 +78,7 @@ async def command_get_chargepoint_settings(
) -> None:
charge_point_id = await get_chargepoint_id(client, args)
settings = await client.get_chargepoint_settings(charge_point_id)
print(json.dumps(settings.to_dict(), indent=4))
print(json.dumps(settings.model_dump(by_alias=True), indent=4))


async def command_set_chargepoint_settings(
Expand All @@ -92,7 +92,7 @@ async def command_set_chargepoint_settings(
settings.down_light = args.downlight
await client.set_chargepoint_settings(settings)
settings = await client.get_chargepoint_settings(charge_point_id)
print(json.dumps(settings.to_dict(), indent=4))
print(json.dumps(settings.model_dump(by_alias=True), indent=4))


async def command_get_connector_settings(
Expand All @@ -109,7 +109,7 @@ async def command_get_connector_settings(
settings = await client.get_chargepoint_connector_settings(
charge_point_id, connector_id
)
res.append(settings.to_dict())
res.append(settings.model_dump(by_alias=True))
print(json.dumps(res, indent=4))


Expand All @@ -133,7 +133,7 @@ async def command_set_connector_settings(
settings = await client.get_chargepoint_connector_settings(
charge_point_id, connector_id
)
print(json.dumps(settings.to_dict(), indent=4))
print(json.dumps(settings.model_dump(by_alias=True), indent=4))


def add_arg_chargepoint(parser, required=False) -> None:
Expand Down
6 changes: 3 additions & 3 deletions chargeamps/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def get_chargepoint_settings(

async def set_chargepoint_settings(self, settings: ChargePointSettings) -> None:
"""Set chargepoint settings"""
payload = settings.to_dict()
payload = settings.model_dump(by_alias=True)
charge_point_id = settings.id
request_uri = f"/api/{API_VERSION}/chargepoints/{charge_point_id}/settings"
await self._put(request_uri, json=payload)
Expand All @@ -153,7 +153,7 @@ async def set_chargepoint_connector_settings(
self, settings: ChargePointConnectorSettings
) -> None:
"""Get all owned chargepoints"""
payload = settings.to_dict()
payload = settings.model_dump(by_alias=True)
charge_point_id = settings.charge_point_id
connector_id = settings.connector_id
request_uri = f"/api/{API_VERSION}/chargepoints/{charge_point_id}/connectors/{connector_id}/settings"
Expand All @@ -163,7 +163,7 @@ async def remote_start(
self, charge_point_id: str, connector_id: int, start_auth: StartAuth
) -> None:
"""Remote start chargepoint"""
payload = start_auth.to_dict()
payload = start_auth.model_dump(by_alias=True)
request_uri = f"/api/{API_VERSION}/chargepoints/{charge_point_id}/connectors/{connector_id}/remotestart"
await self._put(request_uri, json=payload)

Expand Down
3 changes: 0 additions & 3 deletions chargeamps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class FrozenBaseSchema(BaseModel):
frozen=True,
)

def to_dict(self) -> dict:
return self.dict(by_alias=True)


class ChargePointConnector(FrozenBaseSchema):
charge_point_id: str
Expand Down

0 comments on commit 9745df9

Please sign in to comment.