Giter Club home page Giter Club logo

env_canada's Introduction

Environment Canada (env_canada)

PyPI version Snyk rating

This package provides access to various data sources published by Environment and Climate Change Canada.

Weather Observations and Forecasts

ECWeather provides current conditions and forecasts. It automatically determines which weather station to use based on latitude/longitude provided. It is also possible to specify a specific station code of the form AB/s0000123 based on those listed in this CSV file. For example:

import asyncio

from env_canada import ECWeather

ec_en = ECWeather(coordinates=(50, -100))
ec_fr = ECWeather(station_id='ON/s0000430', language='french')

asyncio.run(ec_en.update())

# current conditions
ec_en.conditions

# daily forecasts
ec_en.daily_forecasts

# hourly forecasts
ec_en.hourly_forecasts

# alerts
ec_en.alerts

Weather Radar

ECRadar provides Environment Canada meteorological radar imagery.

import asyncio

from env_canada import ECRadar

radar_coords = ECRadar(coordinates=(50, -100))

# Conditions Available
animated_gif = asyncio.run(radar_coords.get_loop())
latest_png = asyncio.run(radar_coords.get_latest_frame())

Air Quality Health Index (AQHI)

ECAirQuality provides Environment Canada air quality data.

import asyncio

from env_canada import ECAirQuality

aqhi_coords = ECAirQuality(coordinates=(50, -100))

asyncio.run(aqhi_coords.update())

# Data available
aqhi_coords.current
aqhi_coords.forecasts

Water Level and Flow

ECHydro provides Environment Canada hydrometric data.

import asyncio

from env_canada import ECHydro

hydro_coords = ECHydro(coordinates=(50, -100))

asyncio.run(hydro_coords.update())

# Data available
hydro_coords.measurements

Historical Weather Data

ECHistorical provides historical daily weather data. The ECHistorical object is instantiated with a station ID, year, language, format (one of xml or csv) and granularity (hourly, daily data). Once updated asynchronously, historical weather data is contained with the station_data property. If xml is requested, station_data will appear in a dictionary form. If csv is requested, station_data will contain a CSV-readable buffer. For example:

import asyncio

from env_canada import ECHistorical
from env_canada.ec_historical import get_historical_stations

# search for stations, response contains station_ids
coordinates = [53.916944, -122.749444] # [lat, long]

# coordinates: [lat, long]
# radius: km
# limit: response limit, value one of [10, 25, 50, 100]
# The result contains station names and ID values.
stations = asyncio.run(get_historical_stations(coordinates, radius=200, limit=100))

ec_en_xml = ECHistorical(station_id=31688, year=2020, language="english", format="xml")
ec_fr_xml = ECHistorical(station_id=31688, year=2020, language="french", format="xml")
ec_en_csv = ECHistorical(station_id=31688, year=2020, language="english", format="csv")
ec_fr_csv = ECHistorical(station_id=31688, year=2020, language="french", format="csv")

# timeframe argument can be passed to change the granularity
# timeframe=1 hourly (need to create of for every month in that case, use ECHistoricalRange to handle it automatically)
# timeframe=2 daily (default)
ec_en_xml = ECHistorical(station_id=31688, year=2020, month=1, language="english", format="xml", timeframe=1)
ec_en_csv = ECHistorical(station_id=31688, year=2020, month=1, language="english", format="csv", timeframe=1)

asyncio.run(ec_en_xml.update())
asyncio.run(ec_en_csv.update())

# metadata describing the station
ec_en_xml.metadata

# historical weather data, in dictionary form
ec_en_xml.station_data

# csv-generated responses return csv-like station data
import pandas as pd
df = pd.read_csv(ec_en_csv.station_data)

ECHistoricalRange provides historical weather data within a specific range and handles the update by itself.

The ECHistoricalRange object is instantiated with at least a station ID and a daterange. One could add language, and granularity (hourly, daily (default)).

The data can then be used as pandas DataFrame, XML (requires pandas >=1.3.0) and csv

For example :

import pandas as pd
import asyncio
from env_canada import ECHistoricalRange
from env_canada.ec_historical import get_historical_stations
from datetime import datetime

coordinates = ['48.508333', '-68.467667']

stations = pd.DataFrame(asyncio.run(get_historical_stations(coordinates, start_year=2022,
                                                end_year=2022, radius=200, limit=100))).T

ec = ECHistoricalRange(station_id=int(stations.iloc[0,2]), timeframe="daily",
                        daterange=(datetime(2022, 7, 1, 12, 12), datetime(2022, 8, 1, 12, 12)))

ec.get_data()

#yield an XML formated str.
# For more options, use ec.to_xml(*arg, **kwargs) with pandas options
ec.xml

#yield an CSV formated str.
# For more options, use ec.to_csv(*arg, **kwargs) with pandas options
ec.csv

In this example ec.df will be:

Date/Time Longitude (x) Latitude (y) Station Name Climate ID Year Month Day Data Quality Max Temp (°C) Max Temp Flag Min Temp (°C) Min Temp Flag Mean Temp (°C) Mean Temp Flag Heat Deg Days (°C) Heat Deg Days Flag Cool Deg Days (°C) Cool Deg Days Flag Total Rain (mm) Total Rain Flag Total Snow (cm) Total Snow Flag Total Precip (mm) Total Precip Flag Snow on Grnd (cm) Snow on Grnd Flag Dir of Max Gust (10s deg) Dir of Max Gust Flag Spd of Max Gust (km/h) Spd of Max Gust Flag
2022-07-02 -68,47 48,51 POINTE-AU-PERE (INRS) 7056068 2022 7 2 22,8 12,5 17,7 0,3 0 0 26 37
2022-07-03 -68,47 48,51 POINTE-AU-PERE (INRS) 7056068 2022 7 3 21,7 10,1 15,9 2,1 0 0,4 28 50
2022-07-31 -68,47 48,51 POINTE-AU-PERE (INRS) 7056068 2022 7 31 23,5 14,1 18,8 0 0,8 0 23 31
2022-08-01 -68,47 48,51 POINTE-AU-PERE (INRS) 7056068 2022 8 1 23 15 19 0 1 0 21 35

One should note that july 1st is excluded as the time provided contains specific hours, so it yields only data after or at exactly the time provided.

To have all the july 1st data in that case, one can provide a datarange without time: datetime(2022, 7, 7) instead of datetime(2022, 7, 1, 12, 12)

License

The code is available under terms of MIT License

env_canada's People

Contributors

darrenwiens avatar everettsp avatar fabaff avatar gwww avatar infectedroot avatar jm66 avatar kpcofgs avatar marawan31 avatar maruel avatar michaeldavie avatar mrdizzystick avatar onkelbeh avatar snyk-bot avatar stevendinardo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

env_canada's Issues

Feature Request - Add Yesterday's High/Low Temperature

Would you be willing to add new conditions to ec_weather.py that pull yesterday's high and low temperatures? I assume that it would look something like:

"high_temp_yesterday": {
    "xpath": "./yesterdayConditions/temperature[@class="high"]",
    "type": "int",
    "english": "High Temperature Yesterday",
    "french": "Haute température d'hier",
}
"low_temp_yesterday": {
    "xpath": "./yesterdayConditions/temperature[@class="low"]",
    "type": "int",
    "english": "Low Temperature Yesterday",
    "french": "Basse température d'hier",
}

I use your library through your Home Assistant component, and one of the functions that I'm trying to accomplish is the ability to compare yesterday's high temperature to today's forecasted high. Obviously, it's easy to get today's forecasted high, but I can't for the life of me get yesterday's without storing it in an additional helper.

So, if possible, could those two new conditions become sensors in the HA side as well?

Happy to run a test once the changes are merged to make sure it's working.

Thanks!

ECData no longer works and ECWeather returns empty dicts.

Hello,

My script was using ECData from the library to get data for Sherbrooke.

from env_canada import ECData

data = ECData(station_id="QC/s0000681")

degree_symbol = "°"

output_str = 'Sherbrooke: '
output_str += data.conditions['temperature']['value']
output_str += degree_symbol
output_str += data.conditions['temperature']['unit']

print(output_str)

Now I get this error:

from env_canada import ECData
ImportError: cannot import name 'ECData' from 'env_canada' 

So I rewrote the script:

from env_canada import ECWeather

data = ECWeather(station_id="QC/s0000681")

degree_symbol = "°"

output_str = 'Sherbrooke: '
output_str += data.conditions['temperature']['value']
output_str += degree_symbol
output_str += data.conditions['temperature']['unit']

print(output_str)

But I'm getting this error:

output_str += data.conditions['temperature']['value']
KeyError: 'temperature'

And when I check:

In [38]: data = ECWeather(station_id='QC/s0000681', language='english')

In [39]: data.conditions
Out[39]: {}

The data is not there. I tried english and french.
What has changed?

Thanks for any info!

Colours not locked to fixed mm/h values

Got this running as a custom component for the moment. It looks really nice and the time progression helps clear up what's going on a lot.

I notice that the legend colours dance around a bit, so that one frame's precipitation legend value is not necessarily the same as the next (i.e. 64-100 mm/h is violet, then burgundy, 16-24 mm/h is yellow, then orange)... Any way the graphic could use fixed colours for consistency?

DancingScaleValues

xml.etree.ElementTree.ParseError: mismatched tag: line 23, column 8

I'm getting this error after installing either v0.0.25 or v0.0.27

Python 3.7.4 (default, Oct 14 2019, 11:42:47) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from env_canada import ECData
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/env_canada/__init__.py", line 2, in <module>
    from .ec_radar import *
  File "/usr/local/lib/python3.7/site-packages/env_canada/ec_radar.py", line 20, in <module>
    root = et.fromstring(xml_string)
  File "/usr/local/lib/python3.7/xml/etree/ElementTree.py", line 1315, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: mismatched tag: line 23, column 8

This is also related to home-assistant/core#28335

Respond to errors with defined exceptions

If I do something such as:

x=ECWeather(station_id="ON/s1234")
asyncio.run(x.update())

I get an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/glenn/.local/share/asdf/installs/python/3.9.7/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/glenn/.local/share/asdf/installs/python/3.9.7/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/glenn/Development/automation/environment-canada/env_canada/env_canada/ec_weather.py", line 255, in update
    breakpoint()
  File "/Users/glenn/.local/share/asdf/installs/python/3.9.7/lib/python3.9/xml/etree/ElementTree.py", line 1347, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: syntax error: line 1, column 49

The content that was returned is a 404.

All makes sense but would be good to respond with an exception that is more meaningful when giving errors.

Requesting this so that when the HA config_flow is written there can be meaning errors.

FYI, a pattern to define exceptions that you could follow is here: https://github.com/home-assistant-libs/aioshelly/blob/main/aioshelly/__init__.py#L84-L97

Suggest adding normal lows and highs for given location

Hi,

As the title states, it would be useful to include the selected station's normal high and low temperature. I'm not sure what the high and low temperature contained in the ec_en.conditions function refer to. They do not seem to match the high/low normals published on EC Canada's web site for the selected station.

Thank you .

Baobab

Alert Details non-existent

I have been using the environment Canada integration in home assistant and the docs mention a alert details attribute for the sensors but that does not seem to exist. Has this feature been removed or broken? Do you plan on adding it back?

Time progression on new map?

Wondering if there's a way to get time progression on there, it's can be difficult to tell what time we are actually looking at (2 hours ago or now).

Also maybe some kind of legend, I assume light blue is clouds and darker colours indicate precipitation?

Otherwise the new weather map looks quite nice! Really like that it's so much more detailed. 👍

image

issue on running examples

Hi everyone,

In trying to run the example codes, I am not able to import as is stated:
from env_canada import ECHistoricalRange, get_historical_stations

I checked the source code, and it seems these methods have moved. Are these example still supposed to work as is?

Support attribution metadata

Attribution is supported on weather only; for HA attribution is needed on all services used - weather, radar, and air quality.

Make station ID name available

For naming entities in HA it would be nice to automatically be able to use the text name associated with the station. A simple property would suffice.

[feature request] Adding Timeframe option in ECHistorical

Hi,
Is it possible to add timeframe option to ECHistorical ?

I modify the ec_historical.py and test_ec_historical.py like this :

        init_schema = vol.Schema(
            {
                vol.Required("station_id"): int,
                vol.Required("year"): vol.All(
                    int, vol.Range(1840, datetime.today().year)
                ),
                vol.Required("language", default="english"): vol.In(
                    ["english", "french"]
                ),
                vol.Required("format", default="xml"): vol.In(["xml", "csv"]),
                vol.Required("timeframe", default=2): vol.In([1,2,3])
            }
        )

        kwargs = init_schema(kwargs)

        self.station_id = kwargs["station_id"]
        self.year = kwargs["year"]
        self.language = kwargs["language"]
        self.format = kwargs["format"]
        self.timeframe = kwargs["timeframe"]
        self.submit = "Download+Data"

Let me know if you want me to make a pull request

Connection failed to dd.meteo.gc.ca

Not sure if the IP of the API changed or its only a temporary down state, but the dd.meteo.gc.ca or '205.189.10.47', 443 address seems down.

Radar sites out of date

I see Strathmore (aka Calgary) has the older XSM radar which was replaced by CASSM in November.

I found a replacement schedule posted at https://www.canada.ca/en/environment-climate-change/services/weather-general-tools-resources/radar-overview/modernizing-network.html#toc0 which you may want to keep handy, as there are replacements coming up in August, September, October, and November, and indeed into 2023.

Unfortunately I can't find a list of future site locations to suggest for pre-loading the new sites (presumably near the old sites, but that's just an assumption, and there are also new sites being added.

You should add the text summaries

I have been using your component for awhile now. I know it never got merged. Too bad. Canadian weather is always better served by Environment Canada (vs some US based weather service like DarkSky or Yahoo Weather).

You should try and integrate the text summaries of the today forecast and maybe the tonight forecast and tomorrow forecast. That way others could use it to announce via TTS or other notifications.

As example, Dark Sky has a monitored condition for summary = A human-readable text summary.

It is in the EC XML data

<forecastGroup>
<forecast>
<period textForecastName="Today">Monday</period>
<textSummary>
Increasing cloudiness. Snow beginning this afternoon. Amount 2 cm. Wind northeast 20 km/h gusting to 40. High minus 23. Wind chill minus 41 in the morning and minus 34 in the afternoon. Risk of frostbite. UV index 1 or low.
</textSummary>
...
</forecast>
<forecast>
<period textForecastName="Tonight">Monday night</period>
<textSummary>
Snow at times heavy. Local blowing snow overnight. Amount 10 to 15 cm. Wind east 30 km/h gusting to 50. Temperature rising to minus 16 by morning. Wind chill minus 34 in the evening and minus 25 overnight. Risk of frostbite.
</textSummary>
...
</forecast>
...etc

I am no good with programming, otherwise I would try and create a PR for it.

Looking for documentation on use of ec_en.update()

Hello,

Is there a place I can find documentation about what purpose ec_en.update()serves and when/how to use it. I seem to be able to make use of everything else without using it at all in my script. Am I missing something?

Thank you,

Baobab

'cannot identify image file' error while creating radar loop

It looks like Environment and Climate Change Canada changed the time intervals available for the radar layers but the code assumes 10 minutes intervals.

next_frame = frame_times[-1] + datetime.timedelta(minutes=10)

The an example dimension string from the GeoMet WMS.
"2023-01-30T22:12:00Z/2023-01-31T01:12:00Z/PT6M"
The PT6M indicating there is a 6 minute time interval avalabile for this layer.

The 10 minute assumption in the code makes the server return with an XML saying time is outside valid hours which causes

radar = Image.open(BytesIO(radar_bytes)).convert("RGBA")
to create the error "PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f2dfc95d030>"

Unable to get the get_historical_stations

Upon importing ECHistorical and get_historical_stations, the following errors pop up -

  1. NameError: name 'get_historical_stations' is not defined
  2. ImportError: cannot import name 'get_historical_stations' from 'env_canada' (/usr/local/lib/python3.8/dist-packages/env_canada/init.py)

Have tried out pip install, !pip install and !apt install.

error fetching environment_canada AQHI data

The problem
Unexpected error fetching environment_canada AQHI data: invalid literal for int() with base 10:

What version of Home Assistant Core has the issue?
2023.2.4

What was the last working version of Home Assistant Core?
2023.2.3

What type of installation are you running?
Home Assistant Supervised

Integration causing the issue
Environment Canada

Link to integration documentation on our website
https://www.home-assistant.io/integrations/environment_canada

Diagnostics information
config_entry-environment_canada-90973edac7407b00e2058536d993fb26.json.txt

Example YAML snippet
No response

Anything in the logs that might be useful for us?
Logger: homeassistant.components.environment_canada
Source: components/environment_canada/init.py:117
Integration: Environment Canada (documentation, issues)
First occurred: 1:06:34 PM (2 occurrences)
Last logged: 1:11:34 PM

Unexpected error fetching environment_canada AQHI data: invalid literal for int() with base 10: ''
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/components/environment_canada/init.py", line 117, in _async_update_data
await self.ec_data.update()
File "/usr/local/lib/python3.10/site-packages/env_canada/ec_aqhi.py", line 212, in update
self.forecasts["daily"][period] = int(
ValueError: invalid literal for int() with base 10: ''

Additional information

The error appeared in my HA logs after updating from version 2023.2.3 to 2023.2.4:

This error was also reported at home-assistant/core#88027

Snow radar all white

0.5.14 snow radar has nothing showing except white box and legend. No, there's no blizzard;

Screen Shot 2021-11-04 at 11 43 06
)

Air Quality Health Index

Hi @michaeldavie, inspired by env_canada and following the module architecture, I put together aqhi_canada which work pretty much the same as env_canada:

from aqhi_canada.aqhi_data import AqhiData

aqhi = AqhiData(coordinates=(lat, long), language='english')
aqhi.conditions
{'aqhi': {'label': 'Air Quality Health Index', 'value': '2.1'}}

aqhi = AqhiData(coordinates=(lat, long), language='french')
aqhi.conditions
{'aqhi': {'label': 'Cote air santé', 'value': '2.1'}}

But pulling data from different source AQHI_XML_File_List.xml, http://dd.weather.gc.ca/air_quality/aqhi/{cgndb}/observation/realtime/xml/AQ_OBS_{lan}_CURRENT.xml and http://dd.weather.gc.ca/air_quality/aqhi/{cgndb}/observation/realtime/xml/AQ_FCST_{lan}_CURRENT.xml.

At first I thought it could be a different package, but since the data comes from Environment Canada as well, I believe it could be part of the env_canada. Please, let me know your thoughts and if you agree to add aqhi_data.py - I could happily submit a PR.

geogratis is broken in new HA (.112) - using weak SSL (TLS1.0)

Hi, it looks like the base map layer server maps.geogratis.gc.ca is failing to work with HA .112, due to using weak SSL encryption (TLS 1.0).

I put the URL into my browser and it's showing this:
image

I'm guessing they tightened up the SSL in .112 somehow to cause this breakage?

Perhaps swap to using http, until the server figures out how to get into 2010?

Thanks!

Errors not handled

When there is a network error exceptions are thrown that are not caught. More important, further updates to the weather data are not made. From Home Assistant after I get the following error, no more weather updates are made:

2020-07-27 23:39:15 WARNING (MainThread) [homeassistant.helpers.entity] Update of weather.ottawa is taking over 10 seconds
2020-07-27 23:39:16 ERROR (MainThread) [homeassistant.helpers.entity] Update for weather.ottawa fails
Traceback (most recent call last):
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connection.py", line 371, in connect
    ssl_context=context,
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 384, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Users/glenn/.local/share/pyenv/versions/3.7.7/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
  File "/Users/glenn/.local/share/pyenv/versions/3.7.7/lib/python3.7/ssl.py", line 870, in _create
    self.do_handshake()
  File "/Users/glenn/.local/share/pyenv/versions/3.7.7/lib/python3.7/ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
socket.timeout: _ssl.c:1059: The handshake operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/util/retry.py", line 403, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/packages/six.py", line 735, in reraise
    raise value
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 336, in _raise_timeout
    self, url, "Read timed out. (read timeout=%s)" % timeout_value
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='dd.weather.gc.ca', port=443): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 272, in async_update_ha_state
    await self.async_device_update()
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 466, in async_device_update
    self.update  # type: ignore
  File "/Users/glenn/.local/share/pyenv/versions/3.7.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/homeassistant/components/environment_canada/weather.py", line 169, in update
    self.ec_data.update()
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/env_canada/ec_data.py", line 204, in res
    return fun(*args, **kwargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/env_canada/ec_data.py", line 339, in update
    timeout=10)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/Users/glenn/Development/automation/config/pyaml/.venv/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='dd.weather.gc.ca', port=443): Read timed out. (read timeout=10)

Stack Overflow has a good article on how to catch exceptions, with reference back to the requests library: https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module

Precip type property stable

Right now when setting precip_type to auto, it gets overwritten with either rain or snow. Since we are now going to use this property as the value in the select entity we don't want it to change from what we set it to. So, when set to auto and retrieved at a later time it will still be auto.

SSL Certificates fail when pulling Environment Canada

Code:

import asyncio
from env_canada import ECWeather

ec_en = ECWeather(coordinates=(50, -100))
asyncio.run(ec_en.update())

# current conditions
ec_en.conditions

# daily forecasts
ec_en.daily_forecasts

# hourly forecasts
ec_en.hourly_forecasts

# alerts
ec_en.alerts

Expected Outcome:
Returns Conditions, daily / hourly forcasts, and alerts

Actual Outcome:

Exception has occurred: ClientConnectorCertificateError
Cannot connect to host dd.weather.gc.ca:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')]

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

  File "[/Users/a-c0rn/ENDEC/test3.py]()", line 7, in <module>
    asyncio.run(ec_en.update())

Precipitation format has changed in source XML.

<cloudPrecip>
 <textSummary>Nuageux.</textSummary>
 </cloudPrecip>
 <abbreviatedForecast>
 <iconCode format="gif">10</iconCode>
 <pop units="%"/>
 <textSummary>Nuageux</textSummary>
 </abbreviatedForecast>
 ...
 
 <precipitation>
 <textSummary/>
 <precipType start="144" end="155">neige</precipType>
 </precipitation>

SSL Certificates fail when pulling Environment Canada

Code:

import asyncio
from env_canada import ECWeather

ec_en = ECWeather(coordinates=(50, -100))
asyncio.run(ec_en.update())

# current conditions
ec_en.conditions

# daily forecasts
ec_en.daily_forecasts

# hourly forecasts
ec_en.hourly_forecasts

# alerts
ec_en.alerts

Expected Outcome:
Returns Conditions, daily / hourly forcasts, and alerts

Actual Outcome:

Exception has occurred: ClientConnectorCertificateError
Cannot connect to host dd.weather.gc.ca:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')]

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

  File "[/Users/a-c0rn/ENDEC/test3.py]()", line 7, in <module>
    asyncio.run(ec_en.update())

Consider switch to asyncio (aiohttp)

Since this library is being used with Home Assistant which prefers asyncio integrations moving to async libraries would make this a better hass integration library.

This would be a major rewrite of this library though.

Sensors titles are badly formatted in the UI

So, weather sensor requires a name to be able to reference sub-sensors. The name must be something with no spaces, etc. - pretty much some programmatic name. But the sensors display names include main weather sensor name, which makes it look very ugly. Example:

- sensor
  name: my_weather_sensor

results in display names like: my_weather_name Temperature in the UI.

Either add a display name or do not add the main sensor name into titles.

Sunrise / sunset data

I can't seem to find how I can extract sunrise or sunset data from this code. I have taken some time to pour through it and it looks like there might not be anything.

Has anyone been able to accomplish this / point me in the right direction?

Add UV index to monitored conditions

Hi,

Would it be possible to add the "UV index" ./forecastGroup/forecast/uv to the monitored conditions? Already checked in the data source XML and it appears as follows:

<uv category="very high">
  <index>9</index>
  <textSummary>UV index 9 or very high.</textSummary>
</uv>

Thank you!

name: - why remove it?

Most weather platforms have name.

Name gave me (and I am sure others) an easy way to find and maintain sensors. Specifically, I could use the auto-entities Lovelace card and use the sensor.city_name_* to make a card of all my weather sensors

error fetching environment_canada weather data

[homeassistant.components.environment_canada] Unexpected error fetching environment_canada weather data: '<' not supported between instances of 'NoneType' and 'datetime.datetime'
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/components/environment_canada/init.py", line 117, in _async_update_data
await self.ec_data.update()
File "/usr/local/lib/python3.10/site-packages/env_canada/ec_weather.py", line 381, in update
if self.metadata["timestamp"] < max_age:
TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'
home assistant version 2023.2.5
was working in version 2023.2.3

How to print individual items

I am new to python and am having issues printing out individual items from your environment canada section.

Any help would be greatly appreciated.

Thank you

Alternate base map provider

Would it be possible to allow specifying an alternate base map provider to ECRadar for those times (like now) that geogratis.gc.ca is down?
Perhaps openstreetmap.org?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.