Skip to content

Commit

Permalink
feat: query system configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagruenstein committed Sep 22, 2024
1 parent 4560897 commit c76b091
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
5 changes: 1 addition & 4 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import os
from dataclasses import replace

from aiohttp import BasicAuth, ClientSession

Expand All @@ -16,9 +15,7 @@ async def main() -> None:
),
)
) as ipu:
await ipu.set_network_configuration(
replace(await ipu.get_network_configuration(), hostname="robotpdu")
)
print(await ipu.get_system_configuration())
print(await ipu.get_network_configuration())


Expand Down
6 changes: 6 additions & 0 deletions intellinet_pdu_ctrl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
NetworkConfiguration,
OutletCommand,
PDUStatus,
SystemConfiguration,
ThresholdsConfig,
UserVerifyResult,
)
Expand Down Expand Up @@ -131,3 +132,8 @@ async def set_network_configuration(
self, network_config: NetworkConfiguration
) -> None:
await self._post_request(PDUEndpoints.network, data=network_config.to_dict())

async def get_system_configuration(self) -> SystemConfiguration:
return SystemConfiguration.from_xml(
await self._get_request(PDUEndpoints.system)
)
34 changes: 34 additions & 0 deletions intellinet_pdu_ctrl/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,37 @@ def to_dict(self) -> dict[str, str]:
data["dhcp"] = "on"

return data


@dataclass(frozen=True)
class SystemConfiguration:
product_model: str
firmware_version: str
mac_address: str
system_name: str
administrator: str
system_location: str

@classmethod
def from_xml(cls, e: et._Element) -> Self:
product_model = cast(
list[str],
e.xpath(
"//td[strong[normalize-space(text())='Product model']]/following-sibling::td[1]/text()"
),
)[0].strip()
firmware_version = cast(
list[str],
e.xpath(
"//td[strong[normalize-space(text())='Firmware version']]/following-sibling::td[1]/text()"
),
)[0].strip()

return cls(
product_model=product_model,
firmware_version=firmware_version,
mac_address=find_input_value_in_xml(e, "mac"),
system_name=find_input_value_in_xml(e, "sysnm"),
administrator=find_input_value_in_xml(e, "admin"),
system_location=find_input_value_in_xml(e, "loc"),
)

0 comments on commit c76b091

Please sign in to comment.