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

Update version for smart-meter-texas to 0.4.7 #54493

Merged
merged 22 commits into from
Aug 24, 2021
Merged

Conversation

meyerrj
Copy link
Contributor

@meyerrj meyerrj commented Aug 11, 2021

Proposed change

Update library version to fix a broken API call.
Changelog: grahamwetzler/smart-meter-texas@v0.4.0...v0.4.7

Potential fix for #40348

Type of change

  • [ x] Dependency upgrade
  • [ x] Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@homeassistant
Copy link
Contributor

Hi @meyerrj,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@probot-home-assistant
Copy link

Hey there @grahamwetzler, mind taking a look at this pull request as it has been labeled with an integration (smart_meter_texas) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@grahamwetzler
Copy link
Contributor

Thanks again @meyerrj, I just deployed v0.4.4 https://pypi.org/manage/project/smart-meter-texas/release/0.4.4/

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 11, 2021

No problem @grahamwetzler! Thanks for all your work on this project!

@bdraco
Copy link
Member

bdraco commented Aug 11, 2021

You'll need to regenerate requirements

python3 -m script.gen_requirements_all

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see above

@bdraco
Copy link
Member

bdraco commented Aug 12, 2021

Seeing this when testing

2021-08-12 03:15:59 ERROR (MainThread) [homeassistant.components.smart_meter_texas.config_flow] Cannot connect
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
  File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/local/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.8/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/smart_meter_texas/config_flow.py", line 37, in validate_input
    await client.authenticate()
  File "/usr/local/lib/python3.8/site-packages/smart_meter_texas/__init__.py", line 166, in authenticate
    await self._init_websession()
  File "/usr/local/lib/python3.8/site-packages/smart_meter_texas/__init__.py", line 126, in _init_websession
    await self.websession.get(BASE_URL, headers=self._agent_headers())
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host smartmetertexas.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')]

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/smart_meter_texas/config_flow.py", line 58, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/smart_meter_texas/config_flow.py", line 39, in validate_input
    raise CannotConnect from error
homeassistant.components.smart_meter_texas.config_flow.CannotConnect

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 12, 2021

Could the exception possibly be an issue with the SSL library on the client?

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 12, 2021

I found these issues:
https://bugs.python.org/issue36137
https://bugs.python.org/issue36011

It appears that Python's default SSL library on various platforms may be missing some CAs needed to verify some websites, It has some interesting behavior when working through Docker on Windows too.

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 13, 2021

@bdraco Just wanted to follow up. Can you confirm that the SSL error you received wasn't an issue with your Python/SSL environment?

@bdraco
Copy link
Member

bdraco commented Aug 13, 2021

I tried production and dev. Error both places

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 13, 2021

@bdraco Everything I can find on the error points to an issue with the local certificates being out of date or incomplete...

Short of making the library ignore SSL validation (which isn't recommended), I think this issue needs to be resolved in the environment somehow.

@grahamwetzler Another thought may be to import the certifi module and use that ssl context... aio-libs/aiohttp#955 (comment) Thoughts?

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 13, 2021

I found an issue in the site's certificate chain using ssllabs.com to test the site...

I'm now able to reproduce the error with the library itself, so back to testing for a solution.

image

image

@bdraco
Copy link
Member

bdraco commented Aug 13, 2021

Is it a new intermediate certificate that isn't in the version of certifi that home assistant uses?

Does upgrading to certifi 2021.5.30 include it?

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 14, 2021

So, this definitely appears to get even more troublesome than I had anticipated...

The library works with Python on Windows for me just fine, but not Linux. Updating certifi did not help, either.

The only way I can currently get it to work on Linux is by setting the sslcontext.verify_mode to none, or by passing in the certificate chain file when working against smartmetertexas.com.

Also, the SSL certificate chain is correct for the www.smartmetertexas.com domain, but entirely different for smartmetertexas.com. The ssllabs test returns different results too. 🤦‍♂️

image

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

Its setting up now, but the meter is showing unavailable

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 24, 2021

I noticed that the smart meter website can have some latency with getting your meter and meter stats on first setup, and sometimes it takes a while before it actually returns result for your "current" usage. Sometimes I'm only able to query the previous day's information until late in the day.

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

I started the CI. I'll recheck it in 30m and see if it becomes available

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

It's working. Just took 6 minutes to do the first poll

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 24, 2021

Hooray! Thanks for all the help in getting this resolved! I'm excited to get this working on my HA. 😁

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to go if the CI passes

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

If you want to add support for the energy integration in a future PR:

https://developers.home-assistant.io/docs/core/entity/sensor#long-term-statistics

@bdraco bdraco added the smash Indicator this PR is close to finish for merging or closing label Aug 24, 2021
@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

Looks like there are some formatting and a pylint issue to address

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 24, 2021

GitHub's web editor is not well suited for Python. 🤦‍♂️

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

Checked manually, should be good now.

Retesting...

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

testing looks good 👍

@meyerrj
Copy link
Contributor Author

meyerrj commented Aug 24, 2021

Sorry for the trouble with this. My python is admittedly a little rusty after roughly a decade.
This has certainly been a fun deep dive to relearn some lessons.

@bdraco
Copy link
Member

bdraco commented Aug 24, 2021

CI failure is unrelated and being worked on in #55169

@bdraco bdraco merged commit 2932a3d into home-assistant:dev Aug 24, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Aug 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix cla-signed dependency dependency-bump integration: smart_meter_texas small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smart Meter Texas Integration Failed to Connect
4 participants