kdeyev / eyeonwater

HACS repository for EyeOnWater integration
MIT License
26 stars 6 forks source link

Index Out of Range #16

Closed mattmeiser closed 1 year ago

mattmeiser commented 1 year ago

New EOW account for 2 water meters. After installing the integration I get 2 leak detection entities and 2 water consumption entities but nothing has updated. After checking the logs I see:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 239, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 195, in _async_update_data return await self.update_method() File "/config/custom_components/eyeonwater/__init__.py", line 50, in async_update_data await eye_on_water_data.read_meters() File "/config/custom_components/eyeonwater/__init__.py", line 102, in read_meters await meter.read_meter(self.client) File "/config/custom_components/eyeonwater/eow.py", line 102, in read_meter return self._parse_reading_data(data) File "/config/custom_components/eyeonwater/eow.py", line 120, in _parse_reading_data self.reading_data = meters_read[METER_READ_FIELD][meter_index][NEW_LATEST_READ_FIELD] IndexError: list index out of range

mattmeiser commented 1 year ago

Guess this integration isn't going to be supported.

kdeyev commented 1 year ago

Hi @mattmeiser , I have only one meter in my account, so I will need your assistance for being able to investigate/fix this issue. Have you tried to investigate the issue on your end? Please let me know if you are available for collaboration.

mattmeiser commented 1 year ago

I've not really tried to investigate. I'd be willing to collaborate on the issue in a couple weeks--have some vacation coming up.

whitema commented 1 year ago

Hi @kdeyev I also have two meters in my account (culinary and secondary/irrigation) and would love to collaborate to get this integration working.

I'm happy to help however you'd like including working with you to login and parse the output from my account.

kdeyev commented 1 year ago

Hi @kdeyev, That's great. The integration is based on ugly parsing of EOW htmls:

    async def fetch_meters(self, client: "Client"):
        """Returns a list of the meters associated with the account"""
        path = DASHBOARD_ENDPOINT + urllib.parse.quote(self.username)
        data = await client.request(path=path, method="get")

        meters = []
        lines = data.split("\n")
        for line in lines:
            if Meter.info_prefix in line:
                meter_infos = extract_json(line, Meter.info_prefix)
                for meter_info in meter_infos:
                    if METER_ID_FIELD not in meter_info:
                        raise EyeOnWaterAPIError(f"Cannot find {METER_ID_FIELD} field")

                    meter_id = meter_info[METER_ID_FIELD]

                    meter = Meter(meter_id=meter_id, meter_info=meter_info, metric_measurement_system=self.metric_measurement_system)
                    meters.append(meter)

        return meters  

Could you please run the test script and see what's wrong?

whitema commented 1 year ago

Hi @kdeyev , I'm not a developer at all, so hopefully I'm doing this right. I cloned the latest code from Git, updated my userID/password and ran test.py using PyCharm CE.

Here's the output:

/usr/bin/python3 /Users/mw/PycharmProjects/eyeonwater/custom_components/eyeonwater/test.py 2 meters found meter 190240692 shows 354908.13 meter leaks: False Traceback (most recent call last): File "/Users/mw/PycharmProjects/eyeonwater/custom_components/eyeonwater/test.py", line 25, in loop.run_until_complete(main()) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/Users/mw/PycharmProjects/eyeonwater/custom_components/eyeonwater/test.py", line 17, in main await meter.read_meter(client=client) File "/Users/mw/PycharmProjects/eyeonwater/custom_components/eyeonwater/eow.py", line 102, in read_meter return self._parse_reading_data(data) File "/Users/mw/PycharmProjects/eyeonwater/custom_components/eyeonwater/eow.py", line 120, in _parse_reading_data self.reading_data = meters_read[METER_READ_FIELD][meter_index][NEW_LATEST_READ_FIELD] IndexError: list index out of range Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x105e2a130> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x105e76040>, 1.385297083), (<aiohttp.client_proto.ResponseHandler object at 0x105e7eca0>, 2.419574375)]'] connector: <aiohttp.connector.TCPConnector object at 0x105e2a4f0>

Process finished with exit code 1

kdeyev commented 1 year ago

@whitema Thank you. It seems that the first meter worked as expected and the problem with the second meter:

2 meters found
meter 190240692 shows 354908.13

I still have no idea how to fix it, since this integration is a result of reverse engineering. I'm going to be partly unavailable for the next month, but will do my best for fixing the issue with 2 meters. It would be super helpful if you could temporarily share access to your account. If you are ok with it - please reach me bt kn.deev at gmail.

Have a good one.

whitema commented 1 year ago

@kdeyev Happy to share it.

kdeyev commented 1 year ago

The fix is published in v0.0.2-beta.1

kdeyev commented 1 year ago

v0.0.2 has been released