New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add loglinefetch for frontend API call #10579
Changes from 5 commits
f2f40da
0a0c37f
da1f3eb
e7f169d
447bff4
25e0c4c
66ab7cc
ea5e84a
8e11a05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import asyncio | ||
import logging | ||
|
||
from collections import deque | ||
import homeassistant.core as ha | ||
from homeassistant.const import HTTP_NOT_FOUND, HTTP_OK | ||
from homeassistant.components.http import HomeAssistantView | ||
|
@@ -12,7 +13,6 @@ | |
_LOGGER = logging.getLogger(__name__) | ||
CONFIG_PATH = 'zwave_device_config.yaml' | ||
OZW_LOG_FILENAME = 'OZW_Log.txt' | ||
URL_API_OZW_LOG = '/api/zwave/ozwlog' | ||
|
||
|
||
@asyncio.coroutine | ||
|
@@ -26,13 +26,35 @@ def async_setup(hass): | |
hass.http.register_view(ZWaveNodeGroupView) | ||
hass.http.register_view(ZWaveNodeConfigView) | ||
hass.http.register_view(ZWaveUserCodeView) | ||
hass.http.register_static_path( | ||
URL_API_OZW_LOG, hass.config.path(OZW_LOG_FILENAME), False) | ||
hass.http.register_view(ZWaveLogView) | ||
hass.http.register_view(ZWaveConfigWriteView) | ||
|
||
return True | ||
|
||
|
||
class ZWaveLogView(HomeAssistantView): | ||
"""View to read the ZWave log file.""" | ||
|
||
url = r"/api/zwave/ozwlog/{lines:\d+}" | ||
name = "api:zwave:ozwlog" | ||
|
||
@ha.callback | ||
def get(self, request, lines): | ||
"""Retrieve the lines from ZWave log.""" | ||
lines = int(lines) | ||
hass = request.app['hass'] | ||
logfilepath = hass.config.path(OZW_LOG_FILENAME) | ||
|
||
with open(logfilepath, 'r') as logfile: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're not allowed to do I/O in the event loop. Change method signature to Move the opening of file to a new method on this class and call it response = yield from hass.async_add_job(self._get_log, hass, lines) Ignoring pylint for no self use = 👍 |
||
data = (line.rstrip() for line in logfile) | ||
if lines == 0: | ||
loglines = list(data) | ||
else: | ||
loglines = list(deque(data, lines)) | ||
|
||
return self.json('\n'.join(loglines)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't return
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also means that you no longer have to convert your deque to a list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method gives pylint: Method could be a function (no-self-use) Is that safe to ignore? |
||
|
||
|
||
class ZWaveConfigWriteView(HomeAssistantView): | ||
"""View to save the ZWave configuration to zwcfg_xxxxx.xml.""" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (3)