Skip to content

Commit 7c322f0

Browse files
authored
Merge pull request #199 from binarydev/lint_fix
Lint_fix
2 parents 86f5b50 + 8302141 commit 7c322f0

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

custom_components/generac/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
from homeassistant.exceptions import ConfigEntryNotReady
1212

1313
from .api import GeneracApiClient
14-
from .utils import async_client_session
1514
from .const import CONF_PASSWORD
1615
from .const import CONF_USERNAME
1716
from .const import DOMAIN
1817
from .const import PLATFORMS
1918
from .const import STARTUP_MESSAGE
2019
from .coordinator import GeneracDataUpdateCoordinator
20+
from .utils import async_client_session
2121

2222

2323
_LOGGER: logging.Logger = logging.getLogger(__package__)

custom_components/generac/config_flow.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
from homeassistant.core import callback
77

88
from .api import GeneracApiClient
9-
from .utils import async_client_session
109
from .api import InvalidCredentialsException
1110
from .const import CONF_OPTIONS
1211
from .const import CONF_PASSWORD
1312
from .const import CONF_USERNAME
1413
from .const import DOMAIN
15-
14+
from .utils import async_client_session
1615

1716
_LOGGER: logging.Logger = logging.getLogger(__package__)
1817

custom_components/generac/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Helper to create an aiohttp client session for the Generac API."""
2-
3-
from aiohttp import ClientSession, CookieJar
4-
2+
from aiohttp import ClientSession
3+
from aiohttp import CookieJar
54
from homeassistant.core import HomeAssistant
65
from homeassistant.helpers import aiohttp_client
76

@@ -11,4 +10,3 @@ async def async_client_session(hass: HomeAssistant) -> ClientSession:
1110
return aiohttp_client.async_create_clientsession(
1211
hass, cookie_jar=CookieJar(unsafe=True, quote_cookie=False)
1312
)
14-

local_test.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1+
# This script is a standalone test for the Generac API client.
2+
# It logs in to the Generac API using credentials from environment variables
3+
# and prints the device data in JSON format using a custom JSON encoder.
4+
# Make sure to set the environment variables GENERAC_USER and GENERAC_PASS before running this script
5+
# to avoid hardcoding sensitive information in the script.
6+
# This script is intended to be run outside of Home Assistant, for testing purposes.
7+
# It uses the aiohttp library for asynchronous HTTP requests and custom JSON encoding for dataclasses.
8+
# Ensure you have aiohttp installed in your environment.
9+
# If you're using Home Assistant, aiohttp is already included.
10+
# You can install it using pip: pip install aiohttp
111
import asyncio
212
import dataclasses
313
import json
414
import logging
515
import os
6-
import aiohttp
16+
17+
import aiohttp # type: ignore
718
from custom_components.generac.api import GeneracApiClient
819

920
logging.basicConfig(level=logging.DEBUG)
21+
22+
1023
# Your custom JSON encoder
1124
class EnhancedJSONEncoder(json.JSONEncoder):
1225
def default(self, o):
1326
if dataclasses.is_dataclass(o):
1427
return dataclasses.asdict(o)
1528
return super().default(o)
1629

30+
1731
# Async main logic
1832
async def main():
19-
jar = aiohttp.CookieJar(unsafe=True,quote_cookie=False)
33+
jar = aiohttp.CookieJar(unsafe=True, quote_cookie=False)
2034
async with aiohttp.ClientSession(cookie_jar=jar) as session:
2135
api = GeneracApiClient(
2236
os.environ["GENERAC_USER"], os.environ["GENERAC_PASS"], session
@@ -25,6 +39,7 @@ async def main():
2539
device_data = await api.get_device_data()
2640
print(json.dumps(device_data, cls=EnhancedJSONEncoder))
2741

42+
2843
# Run it using asyncio.run (preferred method in Python 3.7+)
2944
if __name__ == "__main__":
30-
asyncio.run(main())
45+
asyncio.run(main())

0 commit comments

Comments
 (0)