Fix State.copy()
This commit is contained in:
parent
03962ab6ae
commit
f8668075d0
2 changed files with 11 additions and 2 deletions
|
@ -381,7 +381,8 @@ class State(object):
|
||||||
def copy(self):
|
def copy(self):
|
||||||
""" Creates a copy of itself. """
|
""" Creates a copy of itself. """
|
||||||
return State(self.entity_id, self.state,
|
return State(self.entity_id, self.state,
|
||||||
dict(self.attributes), self.last_changed)
|
dict(self.attributes), self.last_changed,
|
||||||
|
self.last_updated)
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
""" Converts State to a dict to be used within JSON.
|
""" Converts State to a dict to be used within JSON.
|
||||||
|
|
|
@ -268,7 +268,15 @@ class TestState(unittest.TestCase):
|
||||||
|
|
||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
state = ha.State('domain.hello', 'world', {'some': 'attr'})
|
state = ha.State('domain.hello', 'world', {'some': 'attr'})
|
||||||
self.assertEqual(state, state.copy())
|
# Patch dt_util.utcnow() so we know last_updated got copied too
|
||||||
|
with patch('homeassistant.core.dt_util.utcnow',
|
||||||
|
return_value=dt_util.utcnow() + timedelta(seconds=10)):
|
||||||
|
copy = state.copy()
|
||||||
|
self.assertEqual(state.entity_id, copy.entity_id)
|
||||||
|
self.assertEqual(state.state, copy.state)
|
||||||
|
self.assertEqual(state.attributes, copy.attributes)
|
||||||
|
self.assertEqual(state.last_changed, copy.last_changed)
|
||||||
|
self.assertEqual(state.last_updated, copy.last_updated)
|
||||||
|
|
||||||
def test_dict_conversion(self):
|
def test_dict_conversion(self):
|
||||||
state = ha.State('domain.hello', 'world', {'some': 'attr'})
|
state = ha.State('domain.hello', 'world', {'some': 'attr'})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue