Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
08af9896
Commit
08af9896
authored
5 years ago
by
Robert Van Gorkom
Committed by
Paulus Schoutsen
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixing timezone issue which caused wrong selection of data to be used. (#30011)
parent
5a9e5430
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/withings/common.py
+2
-2
2 additions, 2 deletions
homeassistant/components/withings/common.py
tests/components/withings/test_common.py
+33
-2
33 additions, 2 deletions
tests/components/withings/test_common.py
with
35 additions
and
4 deletions
homeassistant/components/withings/common.py
+
2
−
2
View file @
08af9896
...
@@ -259,8 +259,8 @@ class WithingsDataManager:
...
@@ -259,8 +259,8 @@ class WithingsDataManager:
async
def
update_sleep
(
self
)
->
SleepGetResponse
:
async
def
update_sleep
(
self
)
->
SleepGetResponse
:
"""
Update the sleep data.
"""
"""
Update the sleep data.
"""
end_date
=
int
(
time
.
time
()
)
end_date
=
dt
.
now
()
start_date
=
end_date
-
(
6
*
60
*
60
)
start_date
=
end_date
-
datetime
.
timedelta
(
hours
=
2
)
def
function
():
def
function
():
return
self
.
_api
.
sleep_get
(
startdate
=
start_date
,
enddate
=
end_date
)
return
self
.
_api
.
sleep_get
(
startdate
=
start_date
,
enddate
=
end_date
)
...
...
This diff is collapsed.
Click to expand it.
tests/components/withings/test_common.py
+
33
−
2
View file @
08af9896
"""
Tests for the Withings component.
"""
"""
Tests for the Withings component.
"""
from
datetime
import
timedelta
from
asynctest
import
MagicMock
from
asynctest
import
MagicMock
import
pytest
import
pytest
from
withings_api
import
WithingsApi
from
withings_api
import
WithingsApi
...
@@ -8,15 +10,20 @@ from homeassistant.components.withings.common import (
...
@@ -8,15 +10,20 @@ from homeassistant.components.withings.common import (
NotAuthenticatedError
,
NotAuthenticatedError
,
WithingsDataManager
,
WithingsDataManager
,
)
)
from
homeassistant.config
import
async_process_ha_core_config
from
homeassistant.core
import
HomeAssistant
from
homeassistant.exceptions
import
PlatformNotReady
from
homeassistant.exceptions
import
PlatformNotReady
from
homeassistant.util
import
dt
@pytest.fixture
(
name
=
"
withings_api
"
)
@pytest.fixture
(
name
=
"
withings_api
"
)
def
withings_api_fixture
()
->
WithingsApi
:
def
withings_api_fixture
()
->
WithingsApi
:
"""
Provide withings api.
"""
"""
Provide withings api.
"""
withings_api
=
WithingsApi
.
__new__
(
WithingsApi
)
withings_api
=
WithingsApi
.
__new__
(
WithingsApi
)
withings_api
.
get_measures
=
MagicMock
()
withings_api
.
user_get_device
=
MagicMock
()
withings_api
.
get_sleep
=
MagicMock
()
withings_api
.
measure_get_meas
=
MagicMock
()
withings_api
.
sleep_get
=
MagicMock
()
withings_api
.
sleep_get_summary
=
MagicMock
()
return
withings_api
return
withings_api
...
@@ -101,3 +108,27 @@ async def test_data_manager_call_throttle_disabled(
...
@@ -101,3 +108,27 @@ async def test_data_manager_call_throttle_disabled(
assert
result
==
"
HELLO2
"
assert
result
==
"
HELLO2
"
assert
hello_func
.
call_count
==
2
assert
hello_func
.
call_count
==
2
async
def
test_data_manager_update_sleep_date_range
(
hass
:
HomeAssistant
,
data_manager
:
WithingsDataManager
,
)
->
None
:
"""
Test method.
"""
await
async_process_ha_core_config
(
hass
=
hass
,
config
=
{
"
time_zone
"
:
"
America/Los_Angeles
"
}
)
update_start_time
=
dt
.
now
()
await
data_manager
.
update_sleep
()
call_args
=
data_manager
.
api
.
sleep_get
.
call_args_list
[
0
][
1
]
startdate
=
call_args
.
get
(
"
startdate
"
)
enddate
=
call_args
.
get
(
"
enddate
"
)
assert
startdate
.
tzname
()
==
"
PST
"
assert
enddate
.
tzname
()
==
"
PST
"
assert
startdate
.
tzname
()
==
"
PST
"
assert
update_start_time
<
enddate
assert
enddate
<
update_start_time
+
timedelta
(
seconds
=
1
)
assert
enddate
>
startdate
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment