Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Unable to add fullykiosk instances to homeassistant #54

Closed
lxqikrana opened this issue Sep 29, 2021 · 26 comments · Fixed by #56
Closed

Unable to add fullykiosk instances to homeassistant #54

lxqikrana opened this issue Sep 29, 2021 · 26 comments · Fixed by #56

Comments

@lxqikrana
Copy link

lxqikrana commented Sep 29, 2021

I've been using the fullykiosk integration (via HACS) on homeassistant for a few months now to control two tablets. A few days ago both tablets were marked unreachable in homeassistant. I assumed this was a result of my router changing the IP address of the tablets at some point. I couldn't figure out how to change the IP address for existing entities, so I tried to remove them, uninstall/reinstall fullkykiosk and try to add the tablets again. Now the tablets aren't getting added as fullykiosk instances. On the configuration page I enter this:

IP/Host: http://192.168.0.XXX
Port: 2323
Password: xxxx

It spins for a while and ultimately responds with: " Failed to connect, please try again ".

Looking through the logs, I found this:

Traceback (most recent call last):
File "/config/custom_components/fullykiosk/config_flow.py", line 80, in async_step_user
info = await validate_input(self.hass, user_input)
File "/config/custom_components/fullykiosk/config_flow.py", line 50, in validate_input
deviceInfo = await fully.getDeviceInfo()
File "/usr/local/lib/python3.9/site-packages/fullykiosk/init.py", line 29, in getDeviceInfo
result = await self.sendCommand("deviceInfo")
File "/usr/local/lib/python3.9/site-packages/fullykiosk/init.py", line 21, in sendCommand
data = await self._rh.get(
File "/usr/local/lib/python3.9/site-packages/fullykiosk/init.py", line 129, in get
data = await response.json(content_type="text/html")
File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1097, in json
raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: application/json', url=URL('http://192.168.0.XXX:2323/?cmd=deviceInfo&password=xxxx&type=json')

If I put http://192.168.0.XXX:2323/?cmd=deviceInfo&password=xxxx&type=json into a browser, it loads a json page just fine. Not really sure what to do here. I have uninstalled/reinstalled fullykiosk in HA multiple times, rebooted the RPi between installs as well. Not sure what to do next. Any help would be appreciated. Thanks!

PS: If it helps, I'm using Nabu Casa, but all of the configuration is being done locally while I'm on the same network as HA/the tablets.

@cgarwood
Copy link
Owner

What version of Fully Kiosk Browser is running on the tablet?

@lxqikrana
Copy link
Author

lxqikrana commented Sep 29, 2021

One is running 1.44-play other is running 1.42.5-fire. Neither have been updated recently.

@Se7enair
Copy link

Same problem here

Logger: custom_components.fullykiosk.config_flow
Source: custom_components/fullykiosk/config_flow.py:50
Integration: Fully Kiosk Browser (documentation, issues)
First occurred: 11:01:10 (7 occurrences)
Last logged: 18:16:37

Unexpected exception

Traceback (most recent call last): File "/config/custom_components/fullykiosk/config_flow.py", line 80, in async_step_user info = await validate_input(self.hass, user_input) File "/config/custom_components/fullykiosk/config_flow.py", line 50, in validate_input deviceInfo = await fully.getDeviceInfo() File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 29, in getDeviceInfo result = await self.sendCommand("deviceInfo") File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 21, in sendCommand data = await self._rh.get( File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 129, in get data = await response.json(content_type="text/html") File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1097, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: application/json', url=URL('http://xxxxxxxx:2323/?cmd=deviceInfo&password=xxxxxxxx&type=json')

I think it is since I updated Fully and the android webview
Fully: 1.44-play
webview: 94.0.4606.61
fully integration via hacs: 0.1.4
homeassistant: 2021-9.5

@Se7enair
Copy link

Se7enair commented Sep 30, 2021

Deleted all webview updates, no improvement
Reinstall of fully also no improvements

@lxqikrana
Copy link
Author

Yeah I had not updated the webview or fully (or the fullykiosk integration) before it stopped working. I think something changed in homeassistant that is causing the issue. My install of fully can be remote controlled using the web interface, so it's definitely not fully that is broken.

@Se7enair
Copy link

Which version of homeassistant are you using?

@lxqikrana
Copy link
Author

core-2021.9.7, but I've had the issue for a few days (weeks?) now. The media player functionality stopped working a while ago and I only just got to debugging it. Can't remember exactly how long ago it was.

@Bascht74
Copy link

Bascht74 commented Oct 3, 2021

I get the same error:

Traceback (most recent call last):
  File "/config/custom_components/fullykiosk/config_flow.py", line 80, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/config/custom_components/fullykiosk/config_flow.py", line 50, in validate_input
    deviceInfo = await fully.getDeviceInfo()
  File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 29, in getDeviceInfo
    result = await self.sendCommand("deviceInfo")
  File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 21, in sendCommand
    data = await self._rh.get(
  File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 129, in get
    data = await response.json(content_type="text/html")
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1097, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: application/json', url=URL('http://192.168.17x.xxx:2323/?cmd=deviceInfo&password=xxxxx&type=json')

That mime-type I get with curl as well:

curl -v "http://192.168.175.xxx:2323/?cmd=deviceInfo&password=xxx&type=json"
*   Trying 192.168.175.xxx...
* TCP_NODELAY set
* Connected to 192.168.175.xxx (192.168.175.xxx) port 2323 (#0)
> GET /?cmd=deviceInfo&password=xxx&type=json HTTP/1.1
> Host: 192.168.175.xxx:2323
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Sun, 3 Oct 2021 19:42:18 GMT
< Connection: keep-alive
< Content-Length: 2286
<
{"deviceName":"Galaxy Tab A7","packageName":"de.ozerov.fully","batteryLevel":100,...}* Connection #0 to host 192.168.175.xxx left intact

So it seams that this code is raising the error:

File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 129, in get
    data = await response.json(content_type="text/html")

So the error could be here:
https://github.com/cgarwood/python-fullykiosk/blob/master/fullykiosk/__init__.py

Fully-APP Version : 1.44-play

@github-infohost-org
Copy link

github-infohost-org commented Oct 3, 2021

Definitely this is a problem introduced with Fully Kiosk Browser version 1.44. Downgraded back to version 1.43.8 and all my FKB tablet sensors (RAM, Storage, Screen, App, Wifi statuses, etc etc) in Home Assistant show to be functioning again.

Home Assistant version is 2021.9.7

@Bascht74
Copy link

Bascht74 commented Oct 4, 2021

@github-infohost-org Can you output the result of the curl command above with version 1.43.8? Insert the right IP address and your passport, execute it and post the result (but remove at least the password :-)…

@Se7enair
Copy link

Se7enair commented Oct 4, 2021

I can confirm that it is related to v1.44

Downgraded to 1.43 and everything is working.

@Se7enair
Copy link

Se7enair commented Oct 4, 2021

curl command output with 1.43

curl -v "http://xx:2323/?cmd=deviceInfo&password=xx&type=json"
  *   Trying xx...
  * TCP_NODELAY set
  * Connected to xx(xx.xx) port 2323 (#0)
  > GET /?cmd=deviceInfo&password=xxx&type=json HTTP/1.1
  > Host: xx.xx:2323
  > User-Agent: curl/7.55.1
  > Accept: */*
  >
  < HTTP/1.1 200 OK
  < Content-Type: text/html
  < Date: Mon, 4 Oct 2021 06:19:02 GMT
  < Connection: keep-alive
  < Content-Length: 1605
  <
  {"deviceName":"Galaxy Tab A7","packageName":"de.ozerov.fully","batteryLevel":94,"isPlugged":false,"SSID":"<unknown ssid>","Mac":"xx","ip4":"xx","ip6":"xx","hostname4":"unknown","hostname6":"unknown","wifiSignalLevel":7,"isMobileDataEnabled":false,"screenOrientation":90,"screenBrightness":204,"screenLocked":false,"screenOn":true,"batteryTemperature":29,"plugged":false,"keyguardLocked":false,"locale":"de_DE","serial":"unknown","build":"RP1A.200720.012.T500XXU3BUH3","androidVersion":"11","webviewUA":"Mozilla/5.0 (Linux; Android 11; SM-T500 Build/RP1A.200720.012; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/94.0.4606.61 Safari/537.36","motionDetectorStatus":0,"isDeviceAdmin":true,"isDeviceOwner":false,"internalStorageFreeSpace":14271598592,"internalStorageTotalSpace":23485968384,"ramUsedMemory":2121875456,"ramFreeMemory":712876032,"ramTotalMemory":2834751488,"appUsedMemory":10502616,"appFreeMemory":190823976,"appTotalMemory":201326592,"displayHeightPixels":1200,"displayWidthPixels":2000,"isMenuOpen":false,"topFragmentTag":"","isInDaydream":false,"isRooted":false,"isLicensed":true,"isInScreensaver":false,"kioskLocked":false,"isInForcedSleep":false,"maintenanceMode":false,"kioskMode":false,"startUrl":"http://xx:8123","currentTabIndex":0,"deviceID":"886efb84-9127e89e","appVersionCode":960,"appVersionName":"1.43.6","androidSdk":30,"deviceModel":"SM-T500","deviceManufacturer":"samsung","foregroundApp":"de.ozerov.fully","currentPage":"http://xx:8123/lovelace-yaml/0","lastAppStart":"04.10.21 08:15:59"}* Connection #0 to host xx left intact

@davidepanato
Copy link

I also have the same problem running home assistant 2021.9.7, integration version 0.1.4 and fullykiosk app 1.44-play.
If you need any log/info please let me know.

@github-infohost-org
Copy link

@Bascht74, curl command output with 1.43.8:

curl -v "http://xx:2323/?cmd=deviceInfo&password=xx&type=json"

  • Trying xx...
  • TCP_NODELAY set
  • Connected to xx port 2323 (#0)

GET /?cmd=deviceInfo&password=xx&type=json HTTP/1.1
Host: xx:2323
User-Agent: curl/7.55.1
Accept: /

< HTTP/1.1 200 OK
< Content-Type: text/html
< Date: Mon, 4 Oct 2021 10:41:14 GMT
< Connection: keep-alive
< Content-Length: 1640
<
{"deviceName":"M30","packageName":"de.ozerov.fully","batteryLevel":81,"isPlugged":true,"SSID":""xx"","BSSID":"2c:fd:a1:a2:77:dc","Mac":"00:00:86:92:70:39","ip4":"xx","ip6":"xx","hostname4":"unknown","hostname6":"unknown","wifiSignalLevel":9,"isMobileDataEnabled":false,"screenOrientation":90,"screenBrightness":159,"screenLocked":false,"screenOn":true,"batteryTemperature":25,"plugged":true,"keyguardLocked":false,"locale":"en_US","serial":"unknown","build":"V1.02_20191203","androidVersion":"8.0.0","webviewUA":"Mozilla/5.0 (Linux; Android 8.0.0; KX20 Build/O00623; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/94.0.4606.61 Safari/537.36","motionDetectorStatus":0,"isDeviceAdmin":true,"isDeviceOwner":false,"internalStorageFreeSpace":114863652864,"internalStorageTotalSpace":118942498816,"ramUsedMemory":2077769728,"ramFreeMemory":1816203264,"ramTotalMemory":3893972992,"appUsedMemory":5899096,"appFreeMemory":396754088,"appTotalMemory":402653184,"scopedStorage":false,"displayHeightPixels":1600,"displayWidthPixels":2560,"isMenuOpen":false,"topFragmentTag":"","isInDaydream":false,"isRooted":false,"isLicensed":true,"isInScreensaver":true,"kioskLocked":false,"isInForcedSleep":false,"maintenanceMode":false,"kioskMode":false,"startUrl":"http://xx:8123","currentTabIndex":0,"deviceID":"24874a42-8004258c","appVersionCode":90980,"appVersionName":"1.43.8","androidSdk":26,"deviceModel":"KX20","deviceManufacturer":"Teclast","foregroundApp":"de.ozerov.fully","currentPage":"http://xx:8123/lovelace/0","lastAppStart":"10/4/21 4:10:18 AM","sensorInfo":[]}* Connection #0 to host xx left intact

@cgarwood
Copy link
Owner

cgarwood commented Oct 4, 2021

Looks like they changed the Content-Type encoding from text/html to application/json.
Currently the library is looking for text/html Content-Type. I don't recall if it failed to decode in the past if we didn't specify that Content-Type.

File "/usr/local/lib/python3.9/site-packages/fullykiosk/__init__.py", line 129, in get
    data = await response.json(content_type="text/html")

If someone has some time and wants to test, try modifying that line in that file to just data = await response.json() - I expect that will work for FKB 1.44, but I'm curious if it will still work for 1.43 or older.

@Se7enair
Copy link

Se7enair commented Oct 4, 2021

I am on a supervised installation. So no access to this file.

@lxqikrana
Copy link
Author

I am on a hass install on a raspberry pi, but can't seem to find the file either. There's no /usr/local/lib/python3.9 . Does anyone know where I can find the fullykiosk library?

@cgarwood
Copy link
Owner

cgarwood commented Oct 4, 2021

Depends on how you have HA installed and what version of python you're running (venv or no venv/docker/etc)

@lxqikrana
Copy link
Author

Just running Hass on a raspberry pi (no docker).

I tried looking up the device properties via browser on 1.44-play vs 1.42.5-fire and I see the differences in the output that fully is returning. Assuming that the error in the issue was caused by the changes in fully v1.44, is there any information I can provide to help debug why I can't add the fire tablet (v1.42.5) either? The symptoms are the same - try to add the device with the information, it spins for a bit and then times out with "Failed to connect, please try again".

@github-infohost-org
Copy link

@cgarwood:

Mod does not appear to work on 1.43,
From HA docker terminal:

2021-10-04 11:30:22 ERROR (MainThread) [custom_components.fullykiosk.coordinator] Error requesting x.x.x.x deviceInfo data: 0, messa
ge='Attempt to decode JSON with unexpected mimetype: text/html', url=URL('http://x.x.x.x:2323/?cmd=deviceInfo&password=xx&t
ype=json')

/usr/local/lib/python3.9/site-packages/fullykiosk # ls -al
total 32
drwxr-xr-x 3 root root 4096 Oct 4 11:09 .
drwxr-xr-x 1 root root 4096 Oct 4 11:21 ..
-rw-r--r-- 1 root root 4086 Oct 4 11:09 init.py
-rw-r--r-- 1 root root 4110 Sep 25 12:37 init.py.bak
drwxr-xr-x 2 root root 4096 Oct 4 11:21 pycache
-rw-r--r-- 1 root root 347 Sep 25 12:37 exceptions.py
/usr/local/lib/python3.9/site-packages/fullykiosk # cat init.py
import aiohttp
import json
import logging

from .exceptions import FullyKioskError

_LOGGER = logging.getLogger(name)

RESPONSE_STATUS = "status"
RESPONSE_STATUSTEXT = "statustext"
RESPONSE_ERRORSTATUS = "Error"

class FullyKiosk:
def init(self, session, host, port, password):
self._rh = _RequestsHandler(session, host, port)
self._password = password
self._deviceInfo = None

async def sendCommand(self, cmd, **kwargs):
    data = await self._rh.get(
        cmd=cmd, password=self._password, type="json", **kwargs
    )
    if RESPONSE_STATUS in data and data[RESPONSE_STATUS] == RESPONSE_ERRORSTATUS:
        raise FullyKioskError(RESPONSE_ERRORSTATUS, data[RESPONSE_STATUSTEXT])
    return data

async def getDeviceInfo(self):
    result = await self.sendCommand("deviceInfo")
    self._deviceInfo = result
    return self._deviceInfo

@property
def deviceInfo(self):
    return self._deviceInfo

async def startScreensaver(self):
    await self.sendCommand("startScreensaver")

async def stopScreensaver(self):
    await self.sendCommand("stopScreensaver")

async def screenOn(self):
    await self.sendCommand("screenOn")

async def screenOff(self):
    await self.sendCommand("screenOff")

async def setScreenBrightness(self, brightness):
    await self.sendCommand(
        "setStringSetting", key="screenBrightness", value=brightness
    )

async def setAudioVolume(self, volume, stream=None):
    await self.sendCommand("setAudioVolume", level=volume, stream=stream)

async def restartApp(self):
    await self.sendCommand("restartApp")

async def loadStartUrl(self):
    await self.sendCommand("loadStartUrl")

async def loadUrl(self, url):
    await self.sendCommand("loadUrl", url=url)

async def playSound(self, url, stream=None):
    await self.sendCommand("playSound", url=url, stream=stream)

async def stopSound(self):
    await self.sendCommand("stopSound")

async def toForeground(self):
    await self.sendCommand("toForeground")

async def startApplication(self, application):
    await self.sendCommand("startApplication", package=application)

async def setConfigurationString(self, setting, stringValue):
    await self.sendCommand("setStringSetting", key=setting, value=stringValue)

async def setConfigurationBool(self, setting, boolValue):
    await self.sendCommand("setBooleanSetting", key=setting, value=boolValue)

async def enableLockedMode(self):
    await self.sendCommand("enableLockedMode")

async def disableLockedMode(self):
    await self.sendCommand("disableLockedMode")

async def lockKiosk(self):
    await self.sendCommand("lockKiosk")

async def unlockKiosk(self):
    await self.sendCommand("unlockKiosk")

async def rebootDevice(self):
    await self.sendCommand("rebootDevice")

class _RequestsHandler:
"""Internal class to create FullyKiosk requests"""

def __init__(self, session: aiohttp.ClientSession, host, port):
    self.headers = {"Accept": "application/json"}

    self.session = session
    self.host = host
    self.port = port

async def get(self, **kwargs):
    url = f"http://{self.host}:{self.port}"
    params = []

    for key, value in kwargs.items():
        if value is not None:
            params.append((key, str(value)))

    _LOGGER.debug("Sending request to: %s", url)
    _LOGGER.debug("Parameters: %s", params)
    async with self.session.get(
        url, headers=self.headers, params=params
    ) as response:
        if response.status != 200:
            _LOGGER.warning(
                "Invalid response from Fully Kiosk Browser API: %s", response.status
            )
            raise FullyKioskError(response.status, await response.text())

        data = await response.json()
        _LOGGER.debug(json.dumps(data))
        return data

/usr/local/lib/python3.9/site-packages/fullykiosk #

Will try shortly to upgrade FKB on tablet to 1.44 and see if it starts working...

@github-infohost-org
Copy link

Sorry, those filenames are correct... this editor here is changing the underscores to bold type face!

@github-infohost-org
Copy link

@cgarwood:

Mod works on 1.44!

User-Agent: curl/7.55.1
Accept: /

< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Mon, 4 Oct 2021 17:24:00 GMT
< Connection: keep-alive
< Content-Length: 1669
<
{"deviceName":"M30","packageName":"de.ozerov.fully","batteryLevel":7,"isPlugged":true,"SSID":""xx"","BSSID":"2c:fd:a1:a2:77:dc","Mac":"00:00:86:92:70:39","ip4":"xx","ip6":"xx","hostname4":"xx","hostname6":"xx%wlan0","wifiSignalLevel":9,"isMobileDataEnabled":false,"screenOrientation":90,"screenBrightness":159,"screenLocked":false,"screenOn":true,"batteryTemperature":25,"plugged":true,"keyguardLocked":false,"locale":"en_US","serial":"unknown","build":"V1.02_20191203","androidVersion":"8.0.0","webviewUA":"Mozilla/5.0 (Linux; Android 8.0.0; KX20 Build/O00623; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/94.0.4606.61 Safari/537.36","motionDetectorStatus":0,"isDeviceAdmin":true,"isDeviceOwner":false,"internalStorageFreeSpace":114867417088,"internalStorageTotalSpace":118942498816,"ramUsedMemory":2078658560,"ramFreeMemory":1815314432,"ramTotalMemory":3893972992,"appUsedMemory":4903000,"appFreeMemory":397750184,"appTotalMemory":402653184,"scopedStorage":false,"displayHeightPixels":1600,"displayWidthPixels":2560,"isMenuOpen":false,"topFragmentTag":"","isInDaydream":false,"isRooted":false,"isLicensed":true,"isInScreensaver":true,"kioskLocked":false,"isInForcedSleep":false,"maintenanceMode":false,"kioskMode":false,"startUrl":"http://xx:8123","currentTabIndex":0,"deviceID":"24874a42-8004258c","appVersionCode":90987,"appVersionName":"1.44","androidSdk":26,"deviceModel":"KX20","deviceManufacturer":"Teclast","foregroundApp":"de.ozerov.fully","currentPage":"http://xx:8123/lovelace/0","lastAppStart":"10/4/21 12:20:13 PM","sensorInfo":[]}* Connection #0 to host xx left intact

@Bascht74
Copy link

Bascht74 commented Oct 4, 2021

@cgarwood Hi,
could you use try / Except to execute await response.json() and if that fails, use await response.json(content_type="text/html")

or is there another possibility (e.g. that json() accepts both content types)?

@cgarwood
Copy link
Owner

cgarwood commented Oct 4, 2021

Fix implemented in the python lib, waiting on pypi to process it and will get an update for the component out

@cgarwood
Copy link
Owner

cgarwood commented Oct 4, 2021

New component released published, should be available in HACS shortly or I think you can force HACS to do a re-scan

@lxqikrana
Copy link
Author

@cgarwood Thanks for the quick update!

Just adding this here in case someone else has the same issue that I did. The latest integration still didn't fix my issue. I was seeing errors trying to reconnect to the tablets. I ended up reverting to a backup of HA where I had not yet deleted the fullykiosk integration. In the logs I found the two IPs that HA was trying to talk to, and gave those as permanent IPs for the two tablets. This brought everything back online. Reinstalling all of the latest HA core and supervisor updates has not yet broken anything, so I can only speculate that there is some 'persistent' storage of mac addresses/IP addresses of the fully kiosk tablets that not even an uninstall/reinstall of the fully kiosk integration seems to get rid of. This prevents me from adding 'the same mac address (or some other identifier)' to fullykiosk, even though the integration is empty after a clean install. The main feature request I would make is for there to be a way to change the IP address of the fullykiosk instance after everything has been set up. Everything works now, so I'm happy as a clam. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants