-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Change to use getlogger #36
base: main
Are you sure you want to change the base?
Changes from all commits
f071550
8cb6a49
887492e
fd6dd64
a515292
c3ef09d
4707a0f
9ff02f9
b43af58
95a2a6f
7f1a4da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
.DS_Store | ||
*.pyc | ||
.vscode/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,15 @@ | |
|
||
import logging | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
# Safe importing as this module was not existing on previous versions | ||
# of Home-Assistant. | ||
try: | ||
from homeassistant.helpers import network | ||
except ModuleNotFoundError: | ||
logging.debug('Network module not found.') | ||
_LOGGER.debug('Network module not found.') | ||
|
||
|
||
|
||
def get_url(hass): | ||
|
@@ -29,8 +32,7 @@ def get_url(hass): | |
prefer_external=True, | ||
require_ssl=False) | ||
except AttributeError: | ||
logging.debug( | ||
'Hass version does not have get_url helper, using fall back.') | ||
_LOGGER.debug('Hass version does not have get_url helper, using fall back.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line goes over 80 chars. Do you mind breaking in two similar to how the original was? |
||
|
||
base_url = hass.config.api.base_url | ||
if base_url: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from homeassistant.helpers import entity | ||
from . import api | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, _LOGGER is not used in this file. I think a better change would be removing line 9 and |
||
SENSOR_NAME = 'oura' | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from . import sensor_base | ||
from .helpers import date_helper | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
class MonitoredDayType(enum.Enum): | ||
"""Types of days which can be monitored.""" | ||
|
@@ -152,9 +153,7 @@ def _get_date_by_name(self, date_name): | |
days_ago = None | ||
|
||
if days_ago is None: | ||
logging.info( | ||
f'Oura ({self._name}): ' + | ||
'Unknown day name `{date_name}`, using yesterday.') | ||
_LOGGER.info('Unknown day name ' + date_name + 'using yesterday.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to f-strings and keep self._name. The first change would ensure higher consistency and readability. The second would help in troubleshooting when multiple Oura sensors are added. |
||
days_ago = 1 | ||
|
||
return str(today - datetime.timedelta(days=days_ago)) | ||
|
@@ -253,15 +252,13 @@ def _map_data_to_monitored_days(self, sensor_data, default_attributes=None): | |
backfill += 1 | ||
|
||
if original_date != date_value: | ||
logging.warning( | ||
( | ||
f'Oura ({self._name}): No Oura data found for ' | ||
f'{date_name_title} ({original_date}). Fetching {date_value} ' | ||
'instead.' | ||
) if date_value else ( | ||
f'Unable to find suitable backfill date. No data available.' | ||
) | ||
) | ||
if date_value: | ||
message = 'No Oura data found for '+ date_name_title +' ('+ original_date +'). Fetching '+ date_value + 'instead.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has an issue because there's no space before instead, so the date would merge. Also space before and after spaces are desirable for readability. To solve for all this, let's change to f-strings here and 258. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exceeds 80 chars. Break it into lines of max 80 chars. That's why the original is broken down into concatenated strings. |
||
else: | ||
message = 'Unable to find suitable backfill date. No data available.' | ||
|
||
_LOGGER.warning(message) | ||
|
||
|
||
if daily_data: | ||
date_attributes.update(daily_data) | ||
|
@@ -362,8 +359,7 @@ def parse_sensor_data(self, oura_data, data_param='data', day_param='day'): | |
Oura sensor data for that given day. | ||
""" | ||
if not oura_data or data_param not in oura_data: | ||
logging.error( | ||
f'Oura ({self._name}): Couldn\'t fetch data for Oura ring sensor.') | ||
_LOGGER.error('Couldnt fetch data for Oura ring sensor.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Aso, this is missing |
||
return {} | ||
|
||
sensor_data = oura_data.get(data_param) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import logging | ||
from . import sensor_base_dated | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
class OuraDatedSeriesSensor(sensor_base_dated.OuraDatedSensor): | ||
"""Representation of an Oura Ring sensor with series daily data. | ||
|
@@ -91,15 +92,11 @@ def _map_data_to_monitored_days(self, sensor_data, default_attributes=None): | |
backfill += 1 | ||
|
||
if original_date != date_value: | ||
logging.warning( | ||
( | ||
f'Oura ({self._name}): No Oura data found for ' | ||
f'{date_name_title} ({original_date}). Fetching {date_value} ' | ||
'instead.' | ||
) if date_value else ( | ||
f'Unable to find suitable backfill date. No data available.' | ||
) | ||
) | ||
if date_value: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep the original if logic structure? |
||
message = 'No Oura data found for '+ date_name_title +' ('+ original_date +'). Fetching '+ date_value + 'instead.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: change to f-strings, keep lines below 80 chars and keep Oura ({self._name}) |
||
else: | ||
message = 'Unable to find suitable backfill date. No data available.' | ||
_LOGGER.warning(message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: to keep consistent with the other file (e.g.sensor_base_dated lines 258-260) add a break line before |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto from before: change to f-strings and keep Oura ({self._name}. |
||
if not daily_data: | ||
daily_data = [self._empty_sensor] | ||
|
@@ -166,8 +163,7 @@ def parse_sensor_data(self, oura_data, data_param='data', day_param='day'): | |
Oura sensor data for that given day. | ||
""" | ||
if not oura_data or data_param not in oura_data: | ||
logging.error( | ||
f'Oura ({self._name}): Couldn\'t fetch data for Oura ring sensor.') | ||
_LOGGER.error('Couldnt fetch data for Oura ring sensor.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto: |
||
return {} | ||
|
||
sensor_data = oura_data.get(data_param) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind leaving this change out as it's not related to the _LOGGER change?