Skip to content

Commit bdaf8df

Browse files
OkamotoSenrisenri
andauthored
fix: add darglint (#66)
girasolenergy/SWTeam#18 --------- Co-authored-by: senri <[email protected]>
1 parent 7816a50 commit bdaf8df

File tree

4 files changed

+150
-19
lines changed

4 files changed

+150
-19
lines changed

openems/__main__.py

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
@click.option('--username', default='admin')
1313
@click.option('--password', default='password')
1414
def openems_cli(ctx, server_url, username, password):
15-
"""OpenEMS CLI.""" # noqa: D403
15+
"""Command-line interface for OpenEMS.
16+
17+
Args:
18+
ctx: Click context object.
19+
server_url: OpenEMS server WebSocket URL.
20+
username: Username for authentication.
21+
password: Password for authentication.
22+
"""
1623
client = api.OpenEMSAPIClient(server_url, username, password)
1724
ctx.obj = {
1825
'client': client,
@@ -22,7 +29,11 @@ def openems_cli(ctx, server_url, username, password):
2229
@openems_cli.command()
2330
@click.pass_context
2431
def get_edge_list(ctx):
25-
"""Get OpenEMS Edge List."""
32+
"""Get OpenEMS Edge List.
33+
34+
Args:
35+
ctx: Click context object.
36+
"""
2637
edges = ctx.obj['client'].get_edges()
2738

2839
for edge in edges:
@@ -33,7 +44,12 @@ def get_edge_list(ctx):
3344
@click.pass_context
3445
@click.argument('edge-id')
3546
def get_edge_config(ctx, edge_id):
36-
"""Get OpenEMS Edge Config."""
47+
"""Get OpenEMS Edge Config.
48+
49+
Args:
50+
ctx: Click context object.
51+
edge_id: Edge device ID.
52+
"""
3753
edge_config = ctx.obj['client'].get_edge_config(edge_id)
3854

3955
click.echo(click.style(json.dumps(edge_config, indent=2), fg='green'))
@@ -43,7 +59,12 @@ def get_edge_config(ctx, edge_id):
4359
@click.pass_context
4460
@click.argument('edge-id')
4561
def get_meter_list(ctx, edge_id):
46-
"""Get OpenEMS Meter List."""
62+
"""Get OpenEMS Meter List.
63+
64+
Args:
65+
ctx: Click context object.
66+
edge_id: Edge device ID.
67+
"""
4768
meters = ctx.obj['client'].get_meter_list(edge_id)
4869

4970
for (k, _) in meters.items():
@@ -54,7 +75,12 @@ def get_meter_list(ctx, edge_id):
5475
@click.pass_context
5576
@click.argument('edge-id')
5677
def get_pvinverter_list(ctx, edge_id):
57-
"""Get OpenEMS PVInverter List."""
78+
"""Get OpenEMS PVInverter List.
79+
80+
Args:
81+
ctx: Click context object.
82+
edge_id: Edge device ID.
83+
"""
5884
pvinverters = ctx.obj['client'].get_pvinverter_list(edge_id)
5985

6086
for (k, _) in pvinverters.items():
@@ -66,7 +92,13 @@ def get_pvinverter_list(ctx, edge_id):
6692
@click.argument('edge-id')
6793
@click.argument('component-id')
6894
def get_channel_list(ctx, edge_id, component_id):
69-
"""Get OpenEMS Channel List."""
95+
"""Get OpenEMS Channel List.
96+
97+
Args:
98+
ctx: Click context object.
99+
edge_id: Edge device ID.
100+
component_id: Component ID (e.g., meter ID, inverter ID).
101+
"""
70102
channels = ctx.obj['client'].get_channels_of_component(edge_id, component_id)['channels']
71103
for channel in channels:
72104
click.echo(click.style(f'{component_id}/{channel["id"]}', fg='green'))
@@ -79,7 +111,15 @@ def get_channel_list(ctx, edge_id, component_id):
79111
@click.argument('name')
80112
@click.argument('value')
81113
def update_component_config(ctx, edge_id, component_id, name, value):
82-
"""Update OpenEMS Component Config."""
114+
"""Update OpenEMS Component Config.
115+
116+
Args:
117+
ctx: Click context object.
118+
edge_id: Edge device ID.
119+
component_id: Component ID to update.
120+
name: Configuration parameter name.
121+
value: New value for the configuration parameter.
122+
"""
83123
r = ctx.obj['client'].update_component_config_from_name_value(edge_id, component_id, name, value)
84124
click.echo(click.style(f'{r}', fg='green'))
85125

@@ -92,7 +132,16 @@ def update_component_config(ctx, edge_id, component_id, name, value):
92132
@click.argument('end', type=click.DateTime(['%Y-%m-%d']))
93133
@click.argument('resolution-sec', type=int)
94134
def get_channel_data(ctx, edge_id, channel, start, end, resolution_sec):
95-
"""Get OpenEMS Channel Data."""
135+
"""Get OpenEMS Channel Data.
136+
137+
Args:
138+
ctx: Click context object.
139+
edge_id: Edge device ID.
140+
channel: Channel name (e.g., 'meter0/ActivePower').
141+
start: Start date for data query.
142+
end: End date for data query.
143+
resolution_sec: Data resolution in seconds.
144+
"""
96145
df = ctx.obj['client'].query_historic_timeseries_data(edge_id, start.date(), end.date(), [channel], resolution_sec)
97146

98147
click.echo(click.style(df.to_csv(), fg='green'))

openems/api.py

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ class OpenEMSAPIClient():
1515
"""OpenEMS API Client Class."""
1616

1717
def __init__(self, server_url, username, password):
18-
"""Create client instance and initialize connection helpers."""
18+
"""Create client instance and initialize connection helpers.
19+
20+
Args:
21+
server_url: OpenEMS server WebSocket URL.
22+
username: Username for authentication.
23+
password: Password for authentication.
24+
"""
1925
self.server_url = server_url
2026
self.username = username
2127
self.password = password
@@ -27,7 +33,15 @@ def __del__(self):
2733
self._bridge.shutdown()
2834

2935
async def login(self):
30-
"""Return an authenticated websocket server connection."""
36+
"""Return an authenticated websocket server connection.
37+
38+
Returns:
39+
Server: Authenticated WebSocket server connection.
40+
41+
Raises:
42+
APIError: If authentication fails.
43+
jsonrpc_base.jsonrpc.ProtocolError: If an unexpected protocol error occurs.
44+
"""
3145
if self._server is None or not hasattr(self._server, 'connected') or not self._server.connected:
3246
server = Server(self.server_url)
3347
await server.ws_connect()
@@ -41,7 +55,11 @@ async def login(self):
4155
return self._server
4256

4357
def get_edges(self):
44-
"""Call getEdges API."""
58+
"""Call getEdges API.
59+
60+
Returns:
61+
list: List of edge devices with their configuration.
62+
"""
4563
async def f():
4664
server = await self.login()
4765
page = 0
@@ -62,7 +80,14 @@ async def f():
6280
return self._bridge.run(f)
6381

6482
def get_edge_config(self, edge_id):
65-
"""Call getEdgeConfig API."""
83+
"""Call getEdgeConfig API.
84+
85+
Args:
86+
edge_id: Edge device ID.
87+
88+
Returns:
89+
dict: Edge configuration including components and their settings.
90+
"""
6691
async def f():
6792
server = await self.login()
6893
try:
@@ -82,7 +107,15 @@ async def f():
82107
return self._bridge.run(f)
83108

84109
def get_channels_of_component(self, edge_id, component_id):
85-
"""Call getChannelsOfComponent API."""
110+
"""Call getChannelsOfComponent API.
111+
112+
Args:
113+
edge_id: Edge device ID.
114+
component_id: Component ID to query channels for.
115+
116+
Returns:
117+
dict: Component channels information including channel IDs and metadata.
118+
"""
86119
async def f():
87120
server = await self.login()
88121
try:
@@ -111,7 +144,18 @@ async def f():
111144
return self._bridge.run(f)
112145

113146
def query_historic_timeseries_data(self, edge_id, start, end, channels, resolution_sec=None):
114-
"""Call edgeRpc.queryHistoricTimeseriesData API."""
147+
"""Call edgeRpc.queryHistoricTimeseriesData API.
148+
149+
Args:
150+
edge_id: Edge device ID.
151+
start: Start date for data query.
152+
end: End date for data query.
153+
channels: List of channel names to query (e.g., ['meter0/ActivePower']).
154+
resolution_sec: Optional data resolution in seconds.
155+
156+
Returns:
157+
pd.DataFrame: Time-series data with timestamps as index and channels as columns.
158+
"""
115159
async def f():
116160
server = await self.login()
117161
params = {
@@ -144,7 +188,16 @@ async def f():
144188
return self._bridge.run(f)
145189

146190
def update_component_config(self, edge_id, component_id, properties):
147-
"""Call edgeRpc.updateComponentConfig API."""
191+
"""Call edgeRpc.updateComponentConfig API.
192+
193+
Args:
194+
edge_id: Edge device ID.
195+
component_id: Component ID to update.
196+
properties: List of property dictionaries with 'name' and 'value' keys.
197+
198+
Returns:
199+
dict: Update result from the API.
200+
"""
148201
async def f():
149202
server = await self.login()
150203
try:
@@ -169,6 +222,15 @@ def update_component_config_from_name_value(self, edge_id, component_id, name, v
169222
"""Call edgeRpc.updateComponentConfig API.
170223
171224
This function has name and value argument instead of properties argument of update_component_config method.
225+
226+
Args:
227+
edge_id: Edge device ID.
228+
component_id: Component ID to update.
229+
name: Configuration parameter name.
230+
value: New value for the configuration parameter.
231+
232+
Returns:
233+
dict: Update result from the API.
172234
"""
173235
return self.update_component_config(
174236
edge_id,
@@ -179,13 +241,27 @@ def update_component_config_from_name_value(self, edge_id, component_id, name, v
179241
)
180242

181243
def get_meter_list(self, edge_id):
182-
"""Extract meter list from edge config."""
244+
"""Extract meter list from edge config.
245+
246+
Args:
247+
edge_id: Edge device ID.
248+
249+
Returns:
250+
dict: Dictionary of meter components keyed by component ID.
251+
"""
183252
edge_config = self.get_edge_config(edge_id)
184253
components = edge_config['components']
185254
return dict([(k, v) for (k, v) in components.items() if v['factoryId'].split('.')[0] == 'Meter'])
186255

187256
def get_pvinverter_list(self, edge_id):
188-
"""Extract pvinverter list from edge config."""
257+
"""Extract pvinverter list from edge config.
258+
259+
Args:
260+
edge_id: Edge device ID.
261+
262+
Returns:
263+
dict: Dictionary of PV inverter components keyed by component ID.
264+
"""
189265
edge_config = self.get_edge_config(edge_id)
190266
components = edge_config['components']
191267
return dict([(k, v) for (k, v) in components.items() if v['factoryId'].split('.')[0] == 'PVInverter'])

openems/exceptions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33

44
class APIError(Exception):
5-
"""HTTPError Exception Class."""
5+
"""OpenEMS API error with error code."""
66

77
def __init__(self, message: str, code: int):
8-
"""__init__."""
8+
"""Initialize APIError.
9+
10+
Args:
11+
message: Error message describing the error.
12+
code: Numeric error code from the API.
13+
"""
914
super().__init__(message)
1015
self.code = code

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ deps =
2929
pep8-naming
3030
hacking==7.0.0
3131
flake8-bugbear
32+
darglint
3233

3334
commands = flake8
3435

0 commit comments

Comments
 (0)