forked from edeckers/huemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery_interface.py
50 lines (41 loc) · 1.2 KB
/
discovery_interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright (c) Ely Deckers.
#
# This source code is licensed under the MPL-2.0 license found in the
# LICENSE file in the root directory of this source tree.
import json
from functools import reduce
from huemon.api.api_interface import ApiInterface
class Discovery:
def __init__(self, api: ApiInterface):
raise NotImplementedError("Discoveries is missing its required constructor")
@staticmethod
def _item_to_discovery(item: dict):
return {
"{#NAME}": item["name"],
"{#UNIQUE_ID}": item["uniqueid"],
}
@staticmethod
def _has_state_field(field: str):
return (
lambda item: "state" in item
and field in item["state"]
and "recycle" not in item
)
@staticmethod
def _print_array_as_discovery(items):
print(
json.dumps(
{
"data": reduce(
lambda p, item: [*p, Discovery._item_to_discovery(item)],
items,
[],
)
}
)
)
@staticmethod
def name():
pass
def exec(self, arguments=None):
pass