user2684 / imou_life

Home Assistant custom component for controlling Imou devices
MIT License
128 stars 21 forks source link

APIError: FL1001: Insufficient remaining available licenses #77

Closed scannifn closed 11 months ago

scannifn commented 12 months ago

Version of the custom_component 1.0.13

Configuration

Core 2023.11.3 Supervisor 2023.11.3 Operating System 11.1 Frontend 20231030.2

Logger: custom_components.imou_life
Source: custom_components/imou_life/entity.py:81
Integration: Imou Life (documentation, issues)
First occurred: 18:47:28 (10 occurrences)
Last logged: 18:47:30

APIError: FL1001: Insufficient remaining available licenses, please contact platform customer service. Traceback (most recent call last): File "/config/custom_components/imou_life/entity.py", line 79, in async_added_to_hass await self.sensor_instance.async_update() File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 128, in async_update data = await self.api_client.async_api_deviceSdcardStatus(self._device_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 466, in async_api_deviceSdcardStatus return await self._async_call_api(api, payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 216, in _async_call_api raise APIError(error_message) imouapi.exceptions.APIError: FL1001: Insufficient remaining available licenses, please contact platform customer service.
APIError: FL1001: Insufficient remaining available licenses, please contact platform customer service. Traceback (most recent call last): File "/config/custom_components/imou_life/entity.py", line 79, in async_added_to_hass await self.sensor_instance.async_update() File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 294, in async_update data = await self.api_client.async_api_getDeviceCameraStatus(self._device_id, self._name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 343, in async_api_getDeviceCameraStatus return await self._async_call_api(api, payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 216, in _async_call_api raise APIError(error_message) imouapi.exceptions.APIError: FL1001: Insufficient remaining available licenses, please contact platform customer service.

Describe the bug

Starting from 6th November 2 cameras are not visible anymore.

image

I have checked in https://open.imoulife.com/consoleNew/vas/deviceIn but I do not see licenses exceeded

image

ncosta24 commented 12 months ago

I've the same problem. But get error only with IPC-S42F-D. I've 5 IPC-TA22C-G and get no error

user2684 commented 12 months ago

Hi guys, I'm experiencing the same here. Imou must have changed something on their side since this never happened to me before and my setup has not changed since I'm getting this error. I will try to investigate, if anybody has any news regarding this error please let me know but not sure there is anything we can do on the integration side. Also the error message itself has a different text and meaning compared to the one documented at https://open.imoulife.com/book/en/faq/code.html?h=FL1001

scannifn commented 12 months ago

I confirm that also from my side nothing has been changed in my configuration. The error message is not reporting the right information, in my case, because I have 7 cameras, 10 licenses available and, most important information, 0 licenses exceed! Many thanks in advence to try help us on this “strange” issue.

ncosta24 commented 12 months ago

Nothing change from my side. As I said I've only have problem with 1 camera: my external Imou Cruiser 4MP but with my 5 Imou ranger 2C dont' have any problem

woody4165 commented 11 months ago

Hi @user2684

Same for me, I also wrote, before finding this thread, in the HA community

Same as @ncosta24, I'm getting the issue when using PTZ location service in a Cruiser 4MP

user2684 commented 11 months ago

Ok, so definitely something that has changed on the Imou side which are somehow limiting API calls that our integration is doing. Let's try to understand now if this is related to specific models, to number of concurrent queries, specific operations etc. because I see different and conflicting views on this. I'll investigate and report back

user2684 commented 11 months ago

Based on a first round of tests, at least here, the error shows up when interacting ONLY with one device (out of the 9 that I have). Apparently it is not linked to the specific model, this one is a IPC-C22F-C and the others IPC-C22F-C are working fine. It is not related to the specific API call since any API for that specific device throws that error. My guess is that Imou lowered down the number of devices which can be linked to one account but still it is obscure how they did that. I tried deleting a registered device from Imou Life app but still I get the error. I've opened up a ticket asking for a clarification but I'm not very optimistic, I never got decent answers from Imou support so far. Does this resonate with what you are experiecing?

scannifn commented 11 months ago

Hello @user2684 in my environment I have 7 Imou cams: 5 are IPC-C22E, 1 is IPC-C22E-A and the last one is IPC-C26E-V2. The 2 cams that are not working are 1 of IPC-C22E and the IPC-C26E-V2. I think that the models is not correlated to the issue. In addition as I have already posted I do not have licenses that exceeded. The test that maybe I can do is to reduce the numbers of API calls. Because I have configured them only to have the camera view and I’m not using the rest of the sensors created by the integration. the only problem is to know how to do it. If you can help me maybe we can also try to follow also this route.

user2684 commented 11 months ago

Run some additional tests and confirming it is not model related. It is also not related to the number of API calls or their frequency. I've added a brand new camera and got the error straight away. My guess is that the number of available licenses is no more 10 like it used to be but has been decreased to 5 despite the counter is still showing up 10. I have 6 cameras registered with the integration and only 1 is not working. If I add others, they will not work. You have 7 and 2 are not working. A test case could be to de-register a bunch of them and adding them back to identify this number. Unfortunately mine are in locations not easily accessible so not something I can do easily. A potential workaround could be to create multiple imou accounts (requiring multiple email addresses) and then registering up to 5 or whatever number devices each. Also this would need to be tested, the integration should be able to handle it, if not, can be changed to work in this way but it is a very complex solution and hope there will be simpler ways...

scannifn commented 11 months ago

Indeed, what you say could confirm your hypothesis. Imou probably reduced the licenses to 5 units! Even for me it isn't easy to reach the cameras to do a reset! I have an idea/question: if I created a new Imou account and shared the 2 cameras that don't work in HA and then added it in HA, could it work?

user2684 commented 11 months ago

it may be worth trying. At least in this way you will not mess up anything and does not require physical access to the device. Even if I'm unsure how shared device would work with the current set of APIs we are using. I remember some specific functions and I'm unsure this will eventually use subaccounts which do require different APIs but maybe for what we do this does not come into play. If you want to try it out, let us know the results of the test, if successful could be a great workaround :-) Many thanks

scannifn commented 11 months ago

I have already made the test. I have created a new Imou account and shared from the previous one the 2 cameras that weren't working in HA. From the Imou App, I'm able to see the 2 shared cameras (as expected). I have also created a new Developer account to get the new AppID and AppSecret into https://open.imoulife.com/

I'm able to see the 2 cameras without knowing if they are shared or not.

Just for your information also creating a new Developer account we still get the information that we have 10 licenses available.

2 of them are used also for shared cameras:

image

In HA I added the new "account" by entering the new AppID and AppSecret... the 2 shared cameras have been discovered. But after adding the first one I noticed that the same camera that was already registered before disappeared. I think that it was replaced by the new one. I also added the second camera and I had the same behaviour. Maybe you cannot link the same serial number of the camera at the same time in HA with @user2684 integration.

In addition I have check in the HA log and the error: APIError: FL1001: Insufficient remaining available licenses is disappeared.

I'm able to see the 2 cameras now in HA but... they are very slow to show the camera streaming video!!!! And sometimes nothing appears... the box is white!

When this issue happens this is the error in the HA log:

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403
First occurred: 16:01:33 (4 occurrences)
Last logged: 16:01:37

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 578, in async_get_image
    raise InvalidResponse(f"status code {response.status}")
imouapi.exceptions.InvalidResponse: status code 404

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 94, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 767, in get
    return await self.handle(request, camera)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 785, in handle
    image = await _async_get_image(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 176, in _async_get_image
    else await camera.async_camera_image(width=width, height=height)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/imou_life/camera.py", line 98, in async_camera_image
    return await self.sensor_instance.async_get_image()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 581, in async_get_image
    raise InvalidResponse(f"unable to retrieve image from {url}: {exception}") from exception
imouapi.exceptions.InvalidResponse: unable to retrieve image from https://ali-pano-fk.oss-eu-central-1......jpg...: status code 404

And also this one, that for me it's more relevant for the Imou integration:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/imou_life/camera.py:106
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 16:01:17 (2 occurrences)
Last logged: 16:01:17

[547225311808] Error handling message: Unknown error (unknown_error) Nico from 127.0.0.1 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 843, in ws_camera_stream
    url = await _async_stream_endpoint_url(hass, camera, fmt=msg["format"])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 1006, in _async_stream_endpoint_url
    stream = await camera.async_create_stream()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 558, in async_create_stream
    source = await self.stream_source()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/imou_life/camera.py", line 106, in stream_source
    return await self.sensor_instance.async_get_stream_url()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 661, in async_get_stream_url
    existing_stream = await self.async_get_existing_stream()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 613, in async_get_existing_stream
    data = await self.api_client.async_api_getLiveStreamInfo(self._device_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 576, in async_api_getLiveStreamInfo
    return await self._async_call_api(api, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 210, in _async_call_api
    raise NotAuthorized(f"{error_message}")
imouapi.exceptions.NotAuthorized: OP1009: No right, cannot operate.

I think that there is still something that is not working correctly!

user2684 commented 11 months ago

Thanks for all the tests! I probably need to replicate the same scenario to figure it out because I see too many moving pieces :-)

Device disappearing in HA may be related to the fact that the unique id of the device I generate in the integration cannot be reused in HA, so maybe this is why one is appearing and the same is disappearing on the other side. But this can be solved somehow.

The 404 error sometimes happens while retrieving image previews. The process is to request a snapshot and after a while downloading it from the provided url. Sometimes the Imou server takes more time than expected and hence the 404 since the picture is not ready yet but if this happens consistently then it is something different.

The "No right, cannot operate" is instead when calling API calls not supported by the device but once again if was working in the main account, should work also on the shared one.

So I definitely need to replicate to understand a bit more of what's going on there. But at least I think we can confirm the new limitation of 5 devices I guess. Many thanks

user2684 commented 11 months ago

Hi @scannifn, I run a few tests and these are my findings:

Just checking if my findings match with yours. If it is the case, sharing the device is a good workaround, with the only limitation of having the video stream not working (falling back to snapshot streaming would still be ok).

woody4165 commented 11 months ago

@user2684

  • Despite I've shared all the devices with the other account, it looks like they do not count against the licenses (which makes sense since already consuming a license in the main account, why should they consume another license if it is shared)

This is the answer from Imou tech support that instead said that shared cam counts

Screenshot 2023-12-10 183436

And I'm still having issue when calling ptz-location from a call service in Nodered using the HA device

user2684 commented 11 months ago

Hi, thanks. It must be said their answer is not really answering your question but just saying you can view video streaming. Always like that with their support :-) I finished up my tests and can confirm I was able to mix cameras from the main account with cameras from a secondary account with the current version of the integration without any issue. Specifically, I've shared the camera which was causing the error with a secondary Imou account, removed it from HA and re-added it back using the app id and secret of the secondary Imou account. It shows up correctly and I can control all the switches. Kindly asking if you guys can also verify so we can confirm this workaround is fully working. The issue of the live video streaming is still there so we need to address it in a different way (the secondary imou account has video access through the app so I don't get why we cannot get the same, maybe they are calling different APIs), but at least we are no more blocked by this new license limitation. Many thanks

newwebform commented 11 months ago

i have 7 devices that 5 of them work and 2 wont . i submitted a ticket but it is likely they answered with robot: hello,developers can log in to the Open Platform website and click "Purchased Resources" to view the remaining number of device channel accesses.

i shared the two one that wont work with another account and add them too app via second account and it works now.

scannifn commented 11 months ago

Hello @user2684 I confirm that also for me it's working using this "alternative" method... even if it's not the best but in the end, it's working.

ncosta24 commented 11 months ago

Hello,

I will try to test this alternative method this week.

Thank you

woody4165 commented 11 months ago

@user2684 just tried the workaround sharing the device not working to a new account and it's working fine. Thanks

ncosta24 commented 11 months ago

Test done. Works sharing the now working device from a secondary account. The only error that I'm getting is on camera.record service, but adding a generic camera to the rtsp url works as a workaround

scannifn commented 11 months ago

Test done. Works sharing the now working device from a secondary account. The only error that I'm getting is on camera.record service, but adding a generic camera to the rtsp url works as a workaround

Please could you share the RTSP URL used to add the cameras as Generic Cameras?

ncosta24 commented 11 months ago

Like this: rtsp://192.168.1.81:554/cam/realmonitor?channel=1&subtype=1 image

woody4165 commented 11 months ago

Test done. Works sharing the now working device from a secondary account. The only error that I'm getting is on camera.record service, but adding a generic camera to the rtsp url works as a workaround

Please could you share the RTSP URL used to add the cameras as Generic Cameras?

You can search also in ispyconnect website for imou cam and url for specific cams

scannifn commented 11 months ago

Test done. Works sharing the now working device from a secondary account. The only error that I'm getting is on camera.record service, but adding a generic camera to the rtsp url works as a workaround

Please could you share the RTSP URL used to add the cameras as Generic Cameras?

You can search also in ispyconnect website for imou cam and url for specific cams

Many thanks for the hint.

scannifn commented 11 months ago

rtsp://192.168.1.81:554/cam/realmonitor?channel=1&subtype=1

Still image link is not mandatory?

In the past I already tried to configure it... but the preview image is not visible. Is it normal?

image

ncosta24 commented 11 months ago

Not mandatory

user2684 commented 11 months ago

Thanks all for the tests, so this discussion came to the conclusion that:

I will update the documentation with this information as we will release a new version of the integration. Thanks!