Skip to content

Commit 3e5b4aa

Browse files
committed
Webpack of frontend
1 parent 916a4b6 commit 3e5b4aa

File tree

268 files changed

+5439
-16608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+5439
-16608
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.devcontainer/secrets.yaml
22
__pycache__
3+
node_modules

custom_components/ihcviewer/__init__.py

+54-129
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ async def async_setup(hass, config):
2929
conf = config[DOMAIN]
3030
controller_id = 0
3131
ihc_controller = hass.data[f"ihc{controller_id}"][IHC_CONTROLLER]
32-
hass.http.register_view(IHCLogView(ihc_controller, hass))
33-
hass.http.register_view(IHCProjectView(ihc_controller, hass))
34-
hass.http.register_view(IHCGetValue(ihc_controller, hass))
35-
hass.http.register_view(IHCMapping(hass))
36-
hass.http.register_view(NpmView(hass))
32+
hass.http.register_view(IhcViewerApiView(ihc_controller, hass))
3733

3834
register_frontend(hass)
3935
add_side_panel(hass, conf)
@@ -80,98 +76,47 @@ def register_frontend(hass):
8076
)
8177

8278

83-
class IHCLogView(HomeAssistantView):
84-
"""Get ihc user log."""
79+
class IhcViewerApiView(HomeAssistantView):
80+
"""IHCViewer api requests."""
8581

86-
from ihcsdk.ihccontroller import IHCController
87-
from ihcsdk.ihcclient import IHCSoapClient
88-
89-
url = "/api/ihcviewer/log"
90-
name = "api:ihcviewer:log"
82+
requires_auth = False
83+
name = "api:ihcviewer"
84+
url = r"/api/ihcviewer/{requested_file:.+}"
9185

9286
def __init__(self, ihc_controller, hass):
93-
"""Initilalize the IHCLog view."""
94-
self.ihc_controller = ihc_controller
87+
"""Initilalize the IHCGetValue."""
9588
self.hass = hass
96-
97-
@ha.callback
98-
async def get(self, request):
99-
"""Retrieve IHC log."""
100-
log = await self.hass.async_add_executor_job(self.get_user_log)
101-
return self.json(log)
102-
103-
ihcns = {
104-
"SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/",
105-
"ns1": "utcs",
106-
"ns2": "utcs.values",
107-
"ns3": "utcs.values",
108-
}
109-
110-
def get_user_log(self, language="en"):
111-
"""Get the controller state."""
112-
payload = """<getUserLog1 xmlns="utcs" />
113-
<getUserLog2 xmlns="utcs">0</getUserLog2>
114-
<getUserLog3 xmlns="utcs">{language}</getUserLog3>
115-
""".format(
116-
language=language
117-
)
118-
xdoc = self.ihc_controller.client.connection.soap_action(
119-
"/ws/ConfigurationService", "getUserLog", payload
120-
)
121-
if xdoc is not None:
122-
base64data = xdoc.find(
123-
"./SOAP-ENV:Body/ns1:getUserLog4/ns1:data", IHCLogView.ihcns
124-
).text
125-
if not base64data:
126-
return ""
127-
return base64.b64decode(base64data).decode("UTF-8")
128-
return ""
129-
130-
131-
class IHCProjectView(HomeAssistantView):
132-
"""Get ihc user project."""
133-
134-
from ihcsdk.ihccontroller import IHCController
135-
from ihcsdk.ihcclient import IHCSoapClient
136-
137-
url = "/api/ihcviewer/project"
138-
name = "api:ihcviewer:project"
139-
140-
def __init__(self, ihc_controller, hass):
141-
"""Initilalize the IHCProjectView."""
14289
self.ihc_controller = ihc_controller
143-
self.hass = hass
14490

14591
@ha.callback
146-
async def get(self, request):
147-
"""Retrieve IHC project."""
148-
project = await self.hass.async_add_executor_job(
149-
self.ihc_controller.get_project
150-
)
151-
return web.Response(
152-
body=project, content_type="text/xml", charset="utf-8", status=200
153-
)
92+
async def get(self, request, requested_file): # pylint: disable=unused-argument
93+
"""Handle api Web requests."""
15494

95+
if requested_file == "log":
96+
log = await self.hass.async_add_executor_job(self.get_user_log)
97+
return web.Response(
98+
body=log, content_type="text/plain", charset="utf-8", status=200
99+
)
155100

156-
class IHCGetValue(HomeAssistantView):
157-
"""Get ihc user project."""
101+
if requested_file == "project":
102+
project = await self.hass.async_add_executor_job(
103+
self.ihc_controller.get_project
104+
)
105+
return web.Response(
106+
body=project, content_type="text/xml", charset="utf-8", status=200
107+
)
158108

159-
from ihcsdk.ihccontroller import IHCController
160-
from ihcsdk.ihcclient import IHCSoapClient
109+
if requested_file == "getvalue":
110+
data = request.query
111+
id = int(data.get("id"))
112+
return await self.get_value(id)
161113

162-
url = "/api/ihcviewer/getvalue"
163-
name = "api:ihcviewer:getvalue"
114+
if requested_file == "mapping":
115+
return await self.get_mapping()
164116

165-
def __init__(self, ihc_controller, hass):
166-
"""Initilalize the IHCGetValue."""
167-
self.ihc_controller = ihc_controller
168-
self.hass = hass
117+
return web.Response(status=404)
169118

170-
@ha.callback
171-
async def get(self, request):
172-
"""Get runtime value from IHC controller."""
173-
data = request.query
174-
id = int(data.get("id"))
119+
async def get_value(self, id):
175120
value = await self.hass.async_add_executor_job(
176121
self.ihc_controller.client.get_runtime_value, id
177122
)
@@ -182,57 +127,37 @@ async def get(self, request):
182127
json = {"value": value, "type": type(value).__name__, "entity": entity_id}
183128
return self.json(json)
184129

185-
186-
class IHCMapping(HomeAssistantView):
187-
"""Get mapping of ihc id's to entities."""
188-
189-
url = "/api/ihcviewer/mapping"
190-
name = "api:ihcviewer:mapping"
191-
192-
def __init__(self, hass):
193-
"""Initilalize the IHCGetValue."""
194-
self.hass = hass
195-
196-
@ha.callback
197-
async def get(self, request):
198-
"""Get ihc mapping."""
199-
200-
allstates = await self.hass.async_add_executor_job(self.hass.states.all)
130+
async def get_mapping(self):
201131
global ihcmapping
202132
ihcmapping = {}
133+
allstates = await self.hass.async_add_executor_job(self.hass.states.all)
203134
for state in allstates:
204135
if "ihc_id" in state.attributes:
205136
ihcmapping[state.attributes["ihc_id"]] = state.entity_id
206137
return self.json(ihcmapping)
207138

139+
ihcns = {
140+
"SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/",
141+
"ns1": "utcs",
142+
"ns2": "utcs.values",
143+
"ns3": "utcs.values",
144+
}
208145

209-
class NpmView(HomeAssistantView):
210-
"""npm modules"""
211-
212-
requires_auth = False
213-
name = "ihcviewer_npm"
214-
url = r"/ihcviewer_npm/{requested_file:.+}"
215-
216-
def __init__(self, hass):
217-
"""Initilalize the IHCGetValue."""
218-
self.hass = hass
219-
220-
@ha.callback
221-
async def get(self, request, requested_file): # pylint: disable=unused-argument
222-
"""Handle module Web requests."""
223-
response = await self.hass.async_add_executor_job(
224-
get_file_response, requested_file
146+
def get_user_log(self, language="en"):
147+
payload = """<getUserLog1 xmlns="utcs" />
148+
<getUserLog2 xmlns="utcs">0</getUserLog2>
149+
<getUserLog3 xmlns="utcs">{language}</getUserLog3>
150+
""".format(
151+
language=language
225152
)
226-
return response
227-
228-
229-
def get_file_response(requested_file):
230-
"""Get file."""
231-
232-
dir = os.path.dirname(__file__)
233-
servefile = f"{dir}/node_modules/{requested_file}"
234-
if os.path.exists(servefile):
235-
response = web.FileResponse(servefile)
236-
return response
237-
238-
return web.Response(status=404)
153+
xdoc = self.ihc_controller.client.connection.soap_action(
154+
"/ws/ConfigurationService", "getUserLog", payload
155+
)
156+
if xdoc is not None:
157+
base64data = xdoc.find(
158+
"./SOAP-ENV:Body/ns1:getUserLog4/ns1:data", IhcViewerApiView.ihcns
159+
).text
160+
if not base64data:
161+
return ""
162+
return base64.b64decode(base64data).decode("UTF-8")
163+
return ""

custom_components/ihcviewer/const.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NAME_SHORT = "IHCViewer"
22
DOMAIN = "ihcviewer"
3-
VERSION = "1.2.1"
3+
VERSION = "1.2.3"
44
PROJECT_URL = "https://github.com/dingusdk/haihcviewer/"
55
ISSUE_URL = f"{PROJECT_URL}issues"

0 commit comments

Comments
 (0)