Skip to content

Commit dcf794c

Browse files
committed
Fix formatting
1 parent d72faed commit dcf794c

File tree

5 files changed

+151
-107
lines changed

5 files changed

+151
-107
lines changed

examplev5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example for the usage of the hole module."""
2+
23
import asyncio
34
import json
45

@@ -67,4 +68,4 @@ async def enable():
6768
if __name__ == "__main__":
6869
asyncio.run(main())
6970
asyncio.run(disable())
70-
asyncio.run(enable())
71+
asyncio.run(enable())

examplev6.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example for the usage of the hole module."""
2+
23
import asyncio
34
import json
45
from datetime import datetime
@@ -13,6 +14,7 @@
1314
PORT = 443
1415
VERIFY_TLS = False
1516

17+
1618
async def main():
1719
"""Get the data from a Pi-hole instance."""
1820
async with aiohttp.ClientSession() as session:
@@ -22,14 +24,20 @@ async def main():
2224
password=PASSWORD,
2325
protocol=PROTOCOL,
2426
port=PORT,
25-
verify_tls=VERIFY_TLS
27+
verify_tls=VERIFY_TLS,
2628
) as pihole:
2729
await pihole.get_data()
2830

2931
print("\n=== Version Information ===")
30-
print(f"Core Version: {pihole.core_current} (Latest: {pihole.core_latest}, Update Available: {pihole.core_update})")
31-
print(f"Web Version: {pihole.web_current} (Latest: {pihole.web_latest}, Update Available: {pihole.web_update})")
32-
print(f"FTL Version: {pihole.ftl_current} (Latest: {pihole.ftl_latest}, Update Available: {pihole.ftl_update})")
32+
print(
33+
f"Core Version: {pihole.core_current} (Latest: {pihole.core_latest}, Update Available: {pihole.core_update})"
34+
)
35+
print(
36+
f"Web Version: {pihole.web_current} (Latest: {pihole.web_latest}, Update Available: {pihole.web_update})"
37+
)
38+
print(
39+
f"FTL Version: {pihole.ftl_current} (Latest: {pihole.ftl_latest}, Update Available: {pihole.ftl_update})"
40+
)
3341

3442
print("\n=== Basic Statistics ===")
3543
print(f"Status: {pihole.status}")
@@ -57,22 +65,31 @@ async def main():
5765

5866
print("\n=== Forward Destinations ===")
5967
for upstream in pihole.forward_destinations:
60-
print(f"Name: {upstream['name']}, IP: {upstream['ip']}, Count: {upstream['count']}")
68+
print(
69+
f"Name: {upstream['name']}, IP: {upstream['ip']}, Count: {upstream['count']}"
70+
)
6171

6272
print("\n=== Reply Types ===")
6373
for reply_type, count in pihole.reply_types.items():
6474
print(f"{reply_type}: {count}")
6575

6676
print("\n=== Raw Data ===")
67-
print(json.dumps({
68-
"data": pihole.data,
69-
"blocked_domains": pihole.blocked_domains,
70-
"permitted_domains": pihole.permitted_domains,
71-
"clients": pihole.clients,
72-
"upstreams": pihole.upstreams,
73-
"blocking_status": pihole.blocking_status,
74-
"versions": pihole.versions
75-
}, indent=4, sort_keys=True))
77+
print(
78+
json.dumps(
79+
{
80+
"data": pihole.data,
81+
"blocked_domains": pihole.blocked_domains,
82+
"permitted_domains": pihole.permitted_domains,
83+
"clients": pihole.clients,
84+
"upstreams": pihole.upstreams,
85+
"blocking_status": pihole.blocking_status,
86+
"versions": pihole.versions,
87+
},
88+
indent=4,
89+
sort_keys=True,
90+
)
91+
)
92+
7693

7794
async def toggle_blocking():
7895
"""Example of enabling and disabling Pi-hole blocking."""
@@ -83,18 +100,20 @@ async def toggle_blocking():
83100
password=PASSWORD,
84101
protocol=PROTOCOL,
85102
port=PORT,
86-
verify_tls=VERIFY_TLS
103+
verify_tls=VERIFY_TLS,
87104
) as pihole:
88105
await pihole.get_data()
89106
initial_status = pihole.status
90107
print(f"\nInitial Pi-hole status: {initial_status}")
91108

92109
print("\nDisabling Pi-hole blocking for 60 seconds...")
93110
disable_result = await pihole.disable(duration=60)
94-
111+
95112
await pihole.get_data()
96113
if pihole.status != "disabled":
97-
print(f"ERROR: Failed to disable Pi-hole! Status is still: {pihole.status}")
114+
print(
115+
f"ERROR: Failed to disable Pi-hole! Status is still: {pihole.status}"
116+
)
98117
return
99118
print(f"Successfully disabled Pi-hole. Status: {pihole.status}")
100119
print(f"Disable operation response: {disable_result}")
@@ -104,20 +123,27 @@ async def toggle_blocking():
104123

105124
print("\nEnabling Pi-hole blocking...")
106125
enable_result = await pihole.enable()
107-
126+
108127
await pihole.get_data()
109128
if pihole.status != "enabled":
110-
print(f"ERROR: Failed to enable Pi-hole! Status is still: {pihole.status}")
129+
print(
130+
f"ERROR: Failed to enable Pi-hole! Status is still: {pihole.status}"
131+
)
111132
return
112133
print(f"Successfully enabled Pi-hole. Status: {pihole.status}")
113134
print(f"Enable operation response: {enable_result}")
114135

115136
if pihole.status == initial_status:
116-
print("\nToggle test completed successfully! Pi-hole returned to initial state.")
137+
print(
138+
"\nToggle test completed successfully! Pi-hole returned to initial state."
139+
)
117140
else:
118-
print(f"\nWARNING: Final status ({pihole.status}) differs from initial status ({initial_status})")
141+
print(
142+
f"\nWARNING: Final status ({pihole.status}) differs from initial status ({initial_status})"
143+
)
144+
119145

120146
if __name__ == "__main__":
121147
print(f"=== Pi-hole Statistics as of {datetime.now()} ===")
122148
asyncio.run(main())
123-
asyncio.run(toggle_blocking())
149+
asyncio.run(toggle_blocking())

hole/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from .v6 import HoleV6
33
from .exceptions import HoleError
44

5+
56
def Hole(*args, version=6, **kwargs):
67
"""Factory to get the correct Hole class for Pi-hole v5 or v6."""
78
if version == 5:
89
return HoleV5(*args, **kwargs)
910
elif version == 6:
1011
return HoleV6(*args, **kwargs)
1112
else:
12-
raise HoleError(f"Unsupported Pi-hole version: {version}")
13+
raise HoleError(f"Unsupported Pi-hole version: {version}")

hole/v5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""*hole API Python client."""
2+
23
import asyncio
34
import logging
45
import socket
@@ -211,4 +212,4 @@ def web_latest(self):
211212
@property
212213
def web_update(self):
213214
"""Return wether an update of web interface of the *hole instance is available."""
214-
return self.versions["web_update"]
215+
return self.versions["web_update"]

0 commit comments

Comments
 (0)