Skip to content

Commit c9317c6

Browse files
committed
precommit black/flake8/isort fixes
1 parent c03d608 commit c9317c6

File tree

9 files changed

+335
-215
lines changed

9 files changed

+335
-215
lines changed

.github/workflows/validate.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ jobs:
99
runs-on: "ubuntu-latest"
1010
name: Validate
1111
steps:
12-
- uses: "actions/checkout@v2"
13-
- name: HACS validation
14-
uses: "hacs/integration/action@master"
15-
with:
16-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17-
CATEGORY: "integration"
12+
- uses: "actions/checkout@v2"
13+
- name: HACS validation
14+
uses: "hacs/integration/action@master"
15+
with:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
CATEGORY: "integration"
1818

19-
- name: Hassfest validation
20-
uses: "home-assistant/actions/hassfest@master"
19+
- name: Hassfest validation
20+
uses: "home-assistant/actions/hassfest@master"
2121

2222
style:
2323
runs-on: "ubuntu-latest"
2424
name: Check style formatting
2525
steps:
26-
- uses: "actions/checkout@v2"
27-
- uses: "actions/setup-python@v1"
28-
with:
29-
python-version: "3.x"
30-
- run: python3 -m pip install black
31-
- run: black .
26+
- uses: "actions/checkout@v2"
27+
- uses: "actions/setup-python@v1"
28+
with:
29+
python-version: "3.x"
30+
- run: python3 -m pip install black
31+
- run: black .
3232

3333
pytest:
3434
runs-on: "ubuntu-latest"

.yamllint

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ rules:
5757
type: unix
5858
trailing-spaces:
5959
level: error
60-
truthy:
61-
level: error
60+
truthy: disable

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ previously called `task.unique` with the same `task_name`. The name can be any s
682682
`task.unique` with the same `task_name`.
683683

684684
Note that `task.unique` applies across all global contexts. It's up to you to use a convention
685-
for `task_name` that avoids accidential collisions. For example, you could use a prefix of the
685+
for `task_name` that avoids accidental collisions. For example, you could use a prefix of the
686686
script file name, so that all `task_unique` calls in `FILENAME.py` use a `task_name` that
687687
starts with `"FILENAME."`.
688688

custom_components/pyscript/function.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import logging
66
import traceback
77

8-
from homeassistant.helpers.service import async_get_all_descriptions
9-
108
from .const import LOGGER_PATH
119

1210
_LOGGER = logging.getLogger(LOGGER_PATH + ".handler")
@@ -51,21 +49,25 @@ def __init__(self):
5149
def init(cls, hass):
5250
"""Initialize Function."""
5351
cls.hass = hass
54-
cls.functions.update({
55-
"task.executor": cls.task_executor,
56-
"event.fire": cls.event_fire,
57-
"task.sleep": cls.async_sleep,
58-
"task.unique": cls.task_unique,
59-
"service.call": cls.service_call,
60-
"service.has_service": cls.service_has_service,
61-
})
62-
cls.ast_functions.update({
63-
"log.debug": lambda ast_ctx: ast_ctx.get_logger().debug,
64-
"log.error": lambda ast_ctx: ast_ctx.get_logger().error,
65-
"log.info": lambda ast_ctx: ast_ctx.get_logger().info,
66-
"log.warning": lambda ast_ctx: ast_ctx.get_logger().warning,
67-
"print": lambda ast_ctx: ast_ctx.get_logger().debug,
68-
})
52+
cls.functions.update(
53+
{
54+
"task.executor": cls.task_executor,
55+
"event.fire": cls.event_fire,
56+
"task.sleep": cls.async_sleep,
57+
"task.unique": cls.task_unique,
58+
"service.call": cls.service_call,
59+
"service.has_service": cls.service_has_service,
60+
}
61+
)
62+
cls.ast_functions.update(
63+
{
64+
"log.debug": lambda ast_ctx: ast_ctx.get_logger().debug,
65+
"log.error": lambda ast_ctx: ast_ctx.get_logger().error,
66+
"log.info": lambda ast_ctx: ast_ctx.get_logger().info,
67+
"log.warning": lambda ast_ctx: ast_ctx.get_logger().warning,
68+
"print": lambda ast_ctx: ast_ctx.get_logger().debug,
69+
}
70+
)
6971

7072
@classmethod
7173
async def entity_ids(cls, domain=None):
@@ -148,7 +150,11 @@ async def service_completions(cls, root):
148150
if num_period == 1:
149151
domain, svc_root = root.split(".")
150152
if domain in services:
151-
words |= {f"{domain}.{svc}" for svc in services[domain] if svc.lower().startswith(svc_root)}
153+
words |= {
154+
f"{domain}.{svc}"
155+
for svc in services[domain]
156+
if svc.lower().startswith(svc_root)
157+
}
152158
elif num_period == 0:
153159
words |= {domain for domain in services if domain.lower().startswith(root)}
154160

custom_components/pyscript/global_ctx.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
_LOGGER = logging.getLogger(LOGGER_PATH + ".global_ctx")
1919

20+
2021
class GlobalContext:
2122
"""Define class for global variables and trigger context."""
2223

2324
def __init__(
24-
self,
25-
name,
26-
hass,
27-
global_sym_table=None,
25+
self, name, hass, global_sym_table=None,
2826
):
2927
"""Initialize GlobalContext."""
3028
self.name = name
@@ -100,12 +98,15 @@ async def trigger_init(self, func):
10098
desc = desc[4:].lstrip(" \n\r")
10199
file_desc = io.StringIO(desc)
102100
service_desc = (
103-
yaml.load(file_desc, Loader=yaml.BaseLoader) or OrderedDict()
101+
yaml.load(file_desc, Loader=yaml.BaseLoader)
102+
or OrderedDict()
104103
)
105104
file_desc.close()
106105
except Exception as exc:
107106
self.logger.error(
108-
"Unable to decode yaml doc_string for %s(): %s", func_name, str(exc)
107+
"Unable to decode yaml doc_string for %s(): %s",
108+
func_name,
109+
str(exc),
109110
)
110111
raise HomeAssistantError(exc)
111112
else:
@@ -139,9 +140,7 @@ async def do_service_call(func, ast_ctx, data):
139140
return pyscript_service_handler
140141

141142
self.hass.services.async_register(
142-
DOMAIN,
143-
func_name,
144-
pyscript_service_factory(func_name, func),
143+
DOMAIN, func_name, pyscript_service_factory(func_name, func),
145144
)
146145
async_set_service_schema(self.hass, DOMAIN, func_name, service_desc)
147146
self.services.add(func_name)
@@ -196,7 +195,7 @@ async def do_service_call(func, ast_ctx, data):
196195
func_name,
197196
self.name,
198197
dec_name,
199-
arg_num + 1
198+
arg_num + 1,
200199
)
201200
del trig_args[dec_name]
202201
break
@@ -254,9 +253,7 @@ async def do_service_call(func, ast_ctx, data):
254253
await self.triggers[func_name].stop()
255254

256255
self.triggers_new[func_name] = TrigInfo(
257-
f"{self.name}.{func_name}",
258-
trig_args,
259-
global_ctx=self,
256+
f"{self.name}.{func_name}", trig_args, global_ctx=self,
260257
)
261258

262259
if self.auto_start:
@@ -313,6 +310,7 @@ class GlobalContextMgr:
313310
name_seq = 0
314311

315312
def __init__(self):
313+
"""Report an error if GlobalContextMgr in instantiated."""
316314
_LOGGER.error("GlobalContextMgr class is not meant to be instantiated")
317315

318316
@classmethod
@@ -321,27 +319,33 @@ def init(cls):
321319

322320
def get_global_ctx_factory(ast_ctx):
323321
"""Generate a pyscript.get_global_ctx() function with given ast_ctx."""
322+
324323
async def get_global_ctx():
325324
return ast_ctx.get_global_ctx_name()
325+
326326
return get_global_ctx
327327

328328
def list_global_ctx_factory(ast_ctx):
329329
"""Generate a pyscript.list_global_ctx() function with given ast_ctx."""
330+
330331
async def list_global_ctx():
331332
ctx_names = set(cls.contexts.keys())
332333
curr_ctx_name = ast_ctx.get_global_ctx_name()
333334
ctx_names.discard(curr_ctx_name)
334335
return [curr_ctx_name] + sorted(sorted(ctx_names))
336+
335337
return list_global_ctx
336338

337339
def set_global_ctx_factory(ast_ctx):
338340
"""Generate a pyscript.set_global_ctx() function with given ast_ctx."""
341+
339342
async def set_global_ctx(name):
340343
global_ctx = cls.get(name)
341344
if global_ctx is None:
342345
raise NameError(f"global context '{name}' does not exist")
343346
ast_ctx.set_global_ctx(global_ctx)
344347
ast_ctx.set_logger_name(global_ctx.name)
348+
345349
return set_global_ctx
346350

347351
ast_funcs = {

0 commit comments

Comments
 (0)