home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.14k stars 29.81k forks source link

Workday sensor Installation is not working #93508

Closed maxistviews closed 1 year ago

maxistviews commented 1 year ago

The problem

When I upgraded from 2023.4.6 with the workday integration, I deleted the yaml since it was imported. After this, I deleted the integration. Once I wanted to re-install it, I was greeted with an "Unknown error". No matter which country I add, the same problem remains. The logs mention that 'Canada' object has no attribute 'subdivisions' .

What version of Home Assistant Core has the issue?

core-2023.5.4 core-2023.6.0

What was the last working version of Home Assistant Core?

core-2023.4.6

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Workday

Link to integration documentation on our website

https://www.home-assistant.io/integrations/workday

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: components/workday/config_flow.py:56
First occurred: 10:28:46 PM (2 occurrences)
Last logged: 10:28:49 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/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 227, 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 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/workday/config_flow.py", line 187, in async_step_user
    return await self.async_step_options()
  File "/usr/src/homeassistant/homeassistant/components/workday/config_flow.py", line 233, in async_step_options
    schema = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/workday/config_flow.py", line 56, in add_province_to_schema
    if not obj_holidays.subdivisions:
AttributeError: 'Canada' object has no attribute 'subdivisions'

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @fabaff, @gjohansson-st, mind taking a look at this issue as it has been labeled with an integration (workday) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `workday` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign workday` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


workday documentation workday source (message by IssueLinks)

Anto79-ops commented 1 year ago

Do you get past the first screen? in the first screen you place CA, then on the second setup screen you place the 2 letter province in Subdivisions text box.

maxistviews commented 1 year ago

I do not get to the second screen. I am stuck with "unknown error" in the first screen.

deftdawg commented 1 year ago

A few versions ago, I received a notice that binary_sensor.workday had been migrated and the configuration needed to be removed... I removed the config and restarted.

Not sure when but the migrated workday sensor broke Platform error binary_sensor.workday - cannot import name 'DateLike' from 'holidays' (/usr/local/lib/python3.10/site-packages/holidays/__init__.py) - same error as #80730...

I thought that was related to the province being ONtario, which in the past has been problematically interpreted as a boolean of true if it wasn't quoted in the config... So I deleted the integration and tried to recreate it.

For some strange reason there are 3 entries for Canada: Canada, CA and CAN ... all three are broken with this exact same error about missing subdivisions.

Just to check it's not just a Canada thing, I tried with US: image

The exact same thing happens:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/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 100, 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 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/workday/config_flow.py", line 187, in async_step_user
    return await self.async_step_options()
  File "/usr/src/homeassistant/homeassistant/components/workday/config_flow.py", line 233, in async_step_options
    schema = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/workday/config_flow.py", line 56, in add_province_to_schema
    if not obj_holidays.subdivisions:
AttributeError: 'US' object has no attribute 'subdivisions'

Workday sensors appears to be borked for everything.

deftdawg commented 1 year ago

On a secondary machine I have with a clean install of 2023.5.3 (i.e. not migrated from a binary_sensors.yaml), I don't have Canada/UnitedStates or CAN/USA rather only the expected CA/US country code entries...

On that install I'm able to get this second screen to appear: image

Upgrading to 2023.5.4, the same list of country entries and the same second screen is observed. So on a clean install, no problems.

deftdawg commented 1 year ago
I suspect if we can determine why this is happening, we can get past the missing subdivisions part of the problem. @maxistviews does your countries list also look like the broken one below? Normal Broken
image image
maxistviews commented 1 year ago

I suspect if we can determine why this is happening, we can get past the missing subdivisions part of the problem. @maxistviews does your countries list also look like the broken one below?

|Normal|Broken|

|---|---|

|image|image|

Hey, yup I also see the broken list of countries, cool sleuthing! I wonder if there is something in .storage that could be the issue.

deftdawg commented 1 year ago

There's this in .storage/core.device_registry for me...

      {
        "config_entries": [],
        "connections": [],
        "identifiers": [
          [
            "workday",
            "7e707e0b2ec74b08c963d044a2f54a0f"
          ]
        ],
        "id": "6614fa1a2fb3cbf0c6551fc45a3e6749",
        "orphaned_timestamp": 1685759714.4901247
      }

Nothing else matches workday or either of the hashes (7e707e0b2ec74b08c963d044a2f54a0f/6614fa1a2fb3cbf0c6551fc45a3e6749) in my .storage...

Maybe I'll try deleting it, restarting and seeing what happens.

EDIT: Deleted and restarted, still too many country codes and the same error

deftdawg commented 1 year ago

Well, we can see these multiple entries are somehow coming from python-holidays package here:

https://github.com/dr-prodigy/python-holidays/blob/6ce469d50ff2be42cb4cd4dbc6b150fe02791edf/holidays/countries/__init__.py#LL20C1-L21C1

That's pinned here (Added by this PR: https://github.com/home-assistant/core/pull/89724): https://github.com/home-assistant/core/blob/038b0e6d23db2e17c20bf040804319a698fa3657/homeassistant/components/workday/manifest.json#L15

I'm not sure if updating to the latest release 0.25 would fix it or not.

maxistviews commented 1 year ago

Was worth a shot I guess. I hope it'll be resolved in the next update.

maxistviews commented 1 year ago

I updated to the new version of Home Assistant (2023.6.0) and I am not getting a worse error. As soon as I try to set up the integration, i get this popup:

Config flow could not be loaded: {"message":"Invalid handler specified"}

image

In the log:

Logger: homeassistant.config_entries
Source: config_entries.py:863
First occurred: 5:02:11 PM (3 occurrences)
Last logged: 5:17:25 PM

Error occurred loading flow for integration workday: cannot import name 'country_holidays' from 'holidays' (/usr/local/lib/python3.11/site-packages/holidays/__init__.py)

Im not sure if I should make a new issue out of this as its a new version of Home Assistant.

deftdawg commented 1 year ago

Same for me, I don't think it's a new issue... It's still holidays that busted for us, probably just to update the versions effected in the first post

maxistviews commented 1 year ago

Thats too bad that this hasn't been fixed.

I am giving up on this integration for now and just added a custom binary sensor in my templates:

- binary_sensor:
  - name: "workday_manual"
    unique_id: workday_manual
    state: >
      {{ iif(now().weekday() < 5) }}
    icon: mdi:bag-checked

Right now this just checks if the day is less than 5. (Monday is 0 and Sunday is 6) This is enough for me. This could be expanded infinitely to add days or holiday calendar sensors, so this wont be enough for everyone.

gjohansson-ST commented 1 year ago

All of this doesn't make sense to be honest. It's like it's maintaining a different version that what's pinned in the manifest.

You don't happen to have any custom component or something that use holidays as then it would use that version instead of the one that it's in this manifest

maxistviews commented 1 year ago

I just checked, I don't have that Integration installed.

gjohansson-ST commented 1 year ago

I just checked, I don't have that Integration installed.

I mean any custom component that might be using the holidays package. If you're unsure you can take diagnostics from any integration and paste the section about custom components here.

maxistviews commented 1 year ago

Ah I see what you mean! Yes, Ontario Energy Board is using holidays 0.12. That is a very important integration for me, what can be done to alleviate this issue?

gjohansson-ST commented 1 year ago

Change it's manifest to the same as workday and see if it still works then all good (probably will be). If it doesn't then you will have to choose.

maxistviews commented 1 year ago

So the workday manifest says:

{
  "domain": "workday",
  "name": "Workday",
  "codeowners": ["@fabaff", "@gjohansson-ST"],
  "config_flow": true,
  "documentation": "https://www.home-assistant.io/integrations/workday",
  "iot_class": "local_polling",
  "loggers": [
    "convertdate",
    "hijri_converter",
    "holidays",
    "korean_lunar_calendar"
  ],
  "quality_scale": "internal",
  "requirements": ["holidays==0.21.13"]
}

And the OEB manifest is:

{
  "domain": "ontario_energy_board",
  "name": "Ontario Energy Board",
  "config_flow": true,
  "documentation": "https://github.com/jrfernandes/ontario_energy_board",
  "issue_tracker": "https://github.com/jrfernandes/ontario_energy_board/issues",
  "requirements": [
    "beautifulsoup4==4.10.0",
    "holidays==0.12"
  ],
  "codeowners": [
    "@jrfernandes"
  ],
  "iot_class": "cloud_polling",
  "version": "0.3.2"
}

And I changed it from "0.12" to "0.21.13".

Looks like everything works now! Thanks @gjohansson-ST ! @deftdawg - check your integrations to see if they also have this issue!

deftdawg commented 1 year ago

Yep I have OEB with that too!

gjohansson-ST commented 1 year ago

Very good @maxistviews I will close this