Skip to content
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

Websocket error every few minutes #122

Open
jharris4 opened this issue May 22, 2024 · 21 comments
Open

Websocket error every few minutes #122

jharris4 opened this issue May 22, 2024 · 21 comments

Comments

@jharris4
Copy link

I just installed this integration, and it seems to be working fine, other than I keep getting an error message even when I'm not actually doing anything.

Here's the error I'm seeing in the logs:

2024-05-22 17:52:01.767 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546870360128] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 134, in _async_press_action
    await self.async_press()
  File "/config/custom_components/subaru/button.py", line 154, in async_press
    await self.coordinator.async_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 291, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 414, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 492, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1009, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1071, in __async_calculate_state
    if extra_state_attributes := self.extra_state_attributes:
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/subaru/sensor.py", line 294, in extra_state_attributes
    PressureConverter.convert(
  File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 78, in convert
    return cls.converter_factory(from_unit, to_unit)(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 89, in 
    return lambda val: (val / from_ratio) * to_ratio
                        ~~~~^~~~~~~~~~~~
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
2024-05-22 17:57:02.315 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 414, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 492, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1009, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1071, in __async_calculate_state
    if extra_state_attributes := self.extra_state_attributes:
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/subaru/sensor.py", line 294, in extra_state_attributes
    PressureConverter.convert(
  File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 78, in convert
    return cls.converter_factory(from_unit, to_unit)(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 89, in 
    return lambda val: (val / from_ratio) * to_ratio
                        ~~~~^~~~~~~~~~~~
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
@jharris4
Copy link
Author

I'm in Canada using Metric system, and a quick glance at the code seems to point at a bug specific to this case...

@G-Two
Copy link
Owner

G-Two commented May 24, 2024

Would you please attach your diagnostics output?
image

@jharris4
Copy link
Author

Sure, here you go!

subaru-7d740fd5e86943646274952f43ba30ee-JF2SKEPC4PH408272-0d0e149903e481014081797ee22cc0f6.json

Funny timing I was literally just looking at the issue because I finally have spare time to look at the source to see if I can debug further myself.

Please let me know if there's anything I can do to help debug. Thanks!

@G-Two
Copy link
Owner

G-Two commented May 24, 2024

I think I found the bug:

It looks like the Subaru API doesn't include a recommended tire pressure in your vehicle features. There's a check to see if the dict is populated with the data (should be length of 2, if the data is provided):

if len(info) == 2 and self.entity_description.key in [

But there's a subsequent else block that tries to get the value for a non-existent key and passes it along for conversion:

@jharris4
Copy link
Author

Ah! I was just digging into the pressure unit conversion code, thinking it was something to do with that logic specifically.

Happy to test out any code changes if you think there's an easy fix.

@G-Two
Copy link
Owner

G-Two commented May 24, 2024

I published a prerelease version https://github.com/G-Two/homeassistant-subaru/releases/tag/v0.7.15dev0
It should show as available in HACS. Please give it a try and let me know if it fixes the issue.

@jharris4
Copy link
Author

jharris4 commented May 24, 2024

Awesome thanks, the error seems to be gone!

I am however seeing all 4 tires with pressure displayed as 0.0 hPa, is this to be expected?

It seems that the values for tire pressure are missing as well as the recommended tire pressure. I guess that just isn't supported by subaru in Canada...

@G-Two
Copy link
Owner

G-Two commented May 24, 2024

Looking at your diagnostics output, it looks like there is no reported tire pressure right now. If you drive around for a few minutes and then turn off the vehicle, it should start reporting tire pressure.

Unfortunately, it looks like I may have broke other things with this prerelease, so I'll have to keep working on it later. Feel free to keep using this one, I'll make sure to keep the bug fix for your case in any subsequent release.

@jharris4
Copy link
Author

Interesting, no tire data in history so far, but maybe it'll start showing up with this fix. I'll check after I use the car tomorrow morning.

Thanks again, and sorry to hear that the fix has caused other issues.

@G-Two
Copy link
Owner

G-Two commented May 24, 2024

Apparently "dev" version numbers break things, so I switched to "rc": https://github.com/G-Two/homeassistant-subaru/releases/tag/v0.7.15rc0

This should fix the issue without breaking everything else.

@jharris4
Copy link
Author

I used the car this morning, but all tire pressures are still being reported as 0.

@G-Two
Copy link
Owner

G-Two commented May 24, 2024

Are you using 0.7.15rc0?
Can you attach another diagnostics output?

@jharris4
Copy link
Author

jharris4 commented May 25, 2024

To test the fix I just copied over the new sensor.py into my custom_components then a restart of HA.

I've done a proper update to rc0 now, and here's the latest diagnostics output:

subaru-7d740fd5e86943646274952f43ba30ee-JF2SKEPC4PH408272-0d0e149903e481014081797ee22cc0f6 (2).json

@jharris4
Copy link
Author

I got an email notification that someone mentioned me and asked if the tire pressure was showing up in the MySubaru app.

The answer to that question is no, I wasn't able to see the tire pressure displayed anywhere in the MySubaru app. Maybe it shows up for people in the US but not Canada?

I also wonder if there's some TPMS feature that my Forester is missing. Do people who have tire pressure displaying in the app have anything related to that in the vehicles_features list perhaps?

@G-Two
Copy link
Owner

G-Two commented May 25, 2024

Do you have the ability to view your individual tire pressures inside your vehicle? If so, it's strange that they wouldn't send that information through.

There is a TMPS_MIL listed in my features (2019 Crosstrek PHEV):

      "vehicle_features": [
        "ABS_MIL",
        "AHBL_MIL",
        "ATF_MIL",
        "AWD_MIL",
        "BSD",
        "BSDRCT_MIL",
        "CEL_MIL",
        "EBD_MIL",
        "EOL_MIL",
        "EPAS_MIL",
        "EPB_MIL",
        "ESS_MIL",
        "EYESIGHT",
        "HEVCM_MIL",
        "HEV_MIL",
        "NAV_TOMTOM",
        "OPL_MIL",
        "PHEV",
        "RAB_MIL",
        "RCC",
        "REARBRK",
        "RPOIA",
        "SRS_MIL",
        "TEL_MIL",
        "TIF_36",
        "TIR_35",
        "TPMS_MIL",
        "VDC_MIL",
        "WASH_MIL",
        "g2"
      ],

@jharris4
Copy link
Author

Ok, so it sounds like the vehicle_features could be used to filter out certain things like the tire pressure then!

Unless Subaru provide details around that I could see it being a lot of work to reverse engineer...

Funny that it's spelled tyre in the code, when they only support countries that spell it tire. I wonder where the MySubaru dev team are based.

@jharris4
Copy link
Author

Ahh TIL, here's a reddit thread with Canadians griping about how Subaru commonly sell vehicles without TPMS in Canada.

Kinda makes sense in a way that they don't offer it in Canada. Here in Quebec where I live by law we have to put on snow tires every winter and apparently it costs more to change tires when TPMS enabled, and also TPMS get affected by large temperature fluctuations like we get.

@G-Two
Copy link
Owner

G-Two commented May 26, 2024

Wow, I had no idea Subaru sold cars without TPMS. I updated the latest pre-release to check for TPMS before adding the tire pressure sensors. So this should fix the original bug you reported, as well as eliminate the tire pressure entities from appearing in the first place for unsupported vehicles.

https://github.com/G-Two/homeassistant-subaru/releases/tag/v0.7.15rc1

@jharris4
Copy link
Author

Nice, thanks for looking into this so thoroughly!

One last question: Is there any support for locating the vehicle? I can do that through the MySubaru app, and I’d love to setup some automations for when the car leaves/returns etc…

@G-Two
Copy link
Owner

G-Two commented May 27, 2024

Yes, there should be a device tracker entity in HA that shows your vehicle's last reported location.

@jharris4
Copy link
Author

Oh wow, that's sweet, thanks! I didn't think to look for it because it wasn't on the overview card.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants