Skip to content

Commit

Permalink
chore: merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh committed Feb 21, 2024
2 parents e539f7d + e218fe7 commit 78df842
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
5 changes: 4 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ async def main():
device = devices[0]
print(device)

device_details = await client.get_device_by_device_id(device.device_number)
print(device_details)

# Get Remote Readings from the last three days

selected_date: datetime = datetime.now() - timedelta(days=30)

remote_readings = await client.get_remote_reading(
device.device_number, int(device.device_code), selected_date, selected_date
)
Expand All @@ -76,7 +80,6 @@ async def main():
else:
print("Got no readings")

print(await client.get_devices_by_bp_number())
print(await client.get_electric_bill())
print(await client.get_device_type())
print(await client.get_billing_invoices())
Expand Down
2 changes: 1 addition & 1 deletion iec_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
GET_LAST_METER_READING_URL = IEC_API_BASE_URL + "Device/LastMeterReading/{contract_id}/{bp_number}"
AUTHENTICATE_URL = IEC_API_BASE_URL + "Authentication/{id}/1/-1?customErrorPage=true"
GET_DEVICES_URL = IEC_API_BASE_URL + "Device/{contract_id}"
GET_DEVICES_BY_BP_NUMBER_URL = GET_DEVICES_URL + "/{bp_number}"
GET_DEVICE_BY_DEVICE_ID_URL = GET_DEVICES_URL + "/{device_id}"
GET_DEVICE_TYPE_URL = IEC_API_BASE_URL + "Device/type/{bp_number}/{contract_id}/false"
GET_BILLING_INVOICES = IEC_API_BASE_URL + "billingCollection/invoices/{contract_id}/{bp_number}"
7 changes: 4 additions & 3 deletions iec_api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
GET_CONSUMER_URL,
GET_CONTRACTS_URL,
GET_DEFAULT_CONTRACT_URL,
GET_DEVICE_BY_DEVICE_ID_URL,
GET_DEVICE_TYPE_URL,
GET_DEVICES_BY_BP_NUMBER_URL,
GET_DEVICES_URL,
GET_ELECTRIC_BILL_URL,
GET_LAST_METER_READING_URL,
Expand Down Expand Up @@ -159,12 +159,12 @@ async def get_devices(session: ClientSession, token: JWT, contract_id: str) -> l
return [Device.from_dict(device) for device in response]


async def get_devices_by_bp_number(session: ClientSession, token: JWT, bp_number: str, contract_id: str) -> Devices:
async def get_device_by_device_id(session: ClientSession, token: JWT, contract_id: str, device_id: str) -> Devices:
"""Get Device data response from IEC API."""
return await _get_response_with_descriptor(
session,
token,
GET_DEVICES_BY_BP_NUMBER_URL.format(bp_number=bp_number, contract_id=contract_id),
GET_DEVICE_BY_DEVICE_ID_URL.format(device_id=device_id, contract_id=contract_id),
devices_decoder,
)

Expand All @@ -174,6 +174,7 @@ async def get_device_type(session: ClientSession, token: JWT, bp_number: str, co
# sending get request and saving the response as response object
return await _get_response_with_descriptor(
session, token, GET_DEVICE_TYPE_URL.format(bp_number=bp_number, contract_id=contract_id), device_type_decoder
)


async def get_billing_invoices(session: ClientSession, token: JWT, bp_number: str, contract_id: str) -> GetInvoicesBody:
Expand Down
13 changes: 3 additions & 10 deletions iec_api/iec_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,31 +208,24 @@ async def get_devices(self, contract_id: Optional[str] = None) -> Optional[list[

return await data.get_devices(self._session, self._token, contract_id)

async def get_devices_by_bp_number(
self, bp_number: Optional[str] = None, contract_id: Optional[str] = None
) -> Devices:
async def get_device_by_device_id(self, device_id: str, contract_id: Optional[str] = None) -> Devices:
"""
Get a list of devices for the user
Args:
self: The instance of the class.
bp_number (str): The BP number of the user.
device_id (str): The Device code.
contract_id (str): The Contract ID of the user.
Returns:
list[Device]: List of devices
"""
await self.check_token()

if not bp_number:
bp_number = self._bp_number

assert bp_number, "BP number must be provided"

if not contract_id:
contract_id = self._contract_id

assert contract_id, "Contract ID must be provided"

return await data.get_devices_by_bp_number(self._session, self._token, bp_number, contract_id)
return await data.get_device_by_device_id(self._session, self._token, contract_id, device_id)

async def get_remote_reading(
self,
Expand Down

0 comments on commit 78df842

Please sign in to comment.