Hi guys, I’m trying to use the websocket API, I can authenticate just fine but when I try to send any subsequent command (except for get_config ) I get a unkwon_error response (example: { id: 1, type: 'subscribe_events' } . Am I missing something obvious?
If I send the get_config command I get back the config as expected.
In the logs I see:
Dec 22 10:59:28 home-assistant hass[16749]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/websocket_api/connection.py", line 66, i
Dec 22 10:59:28 home-assistant hass[16749]: handler(self.hass, self, schema(msg))
Dec 22 10:59:28 home-assistant hass[16749]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/websocket_api/commands.py", line 161, in
Dec 22 10:59:28 home-assistant hass[16749]: entity_perm = connection.user.permissions.check_entity
Dec 22 10:59:28 home-assistant hass[16749]: AttributeError: 'NoneType' object has no attribute 'permissions'
For completeness, here’s my code:
const ws = new WebSocket('wss://xxxxxxxxxx/api/websocket');
const j = JSON.stringify;
let id = 1;
ws.onmessage = e => {
const data = JSON.parse(e.data);
switch (data.type) {
case 'auth_required':
ws.send(
j({
type: 'auth',
api_password: 'xxxxxxxxx',
})
);
break;
case 'auth_ok':
ws.send(
j({
id: id++,
type: 'subscribe_events',
})
);
break;
default:
alert(e.data);
}
};
I noticed it works just fine if I use access_token “stolen” form the front-end.
Now I’m trying to implement a proper authentication system but after I get an authorization code and try to request an access_token I get unsupported_grant_type
I experience the same ‘unknown error’ when I subscribe to event bus using api_password during authentication. This error occurs in my current version 0.84.6 (141) and it worked so far in my previous versions (last before upgrade was 0.82.1).
The issue can be easy simulated using Chrome extension, I use ‘Smart Websocket Client’. After making connection to your URL and using api_password to authenticate will throw the unknown error during the next step subscribe_events.
To resolve, you need to generate a long-lived token under frontend profile and use this token instead then the step subscribe_events works: