diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index cf462a029e0..871d105a3f0 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -26,7 +26,7 @@ TIMER_INTERVAL = 10 # seconds # every minute. assert 60 % TIMER_INTERVAL == 0, "60 % TIMER_INTERVAL should be 0!" -State = namedtuple("State", ['state','last_changed']) +State = namedtuple("State", ['state', 'last_changed', 'attributes']) def start_home_assistant(eventbus): """ Start home assistant. """ @@ -181,21 +181,29 @@ class StateMachine(object): """ List of categories which states are being tracked. """ return self.states.keys() - def set_state(self, category, new_state): - """ Set the state of a category, add category if it does not exist. """ + def set_state(self, category, new_state, attributes=None): + """ Set the state of a category, add category if it does not exist. + + Attributes is an optional dict to specify attributes of this state. """ + + attributes = attributes or {} self.lock.acquire() # Add category if it does not exist if category not in self.states: - self.states[category] = State(new_state, datetime.now()) + self.states[category] = State(new_state, datetime.now(), + attributes) # Change state and fire listeners else: old_state = self.states[category] - if old_state.state != new_state: - self.states[category] = State(new_state, datetime.now()) + if old_state.state != new_state or \ + old_state.attributes != attributes: + + self.states[category] = State(new_state, datetime.now(), + attributes) self.eventbus.fire(EVENT_STATE_CHANGED, {'category':category, diff --git a/homeassistant/actors.py b/homeassistant/actors.py index 36f19b8c886..b9e06a3ede8 100644 --- a/homeassistant/actors.py +++ b/homeassistant/actors.py @@ -19,7 +19,7 @@ import homeassistant.util as util from homeassistant.observers import ( STATE_CATEGORY_SUN, SUN_STATE_BELOW_HORIZON, SUN_STATE_ABOVE_HORIZON, STATE_CATEGORY_ALL_DEVICES, DEVICE_STATE_HOME, DEVICE_STATE_NOT_HOME, - STATE_CATEGORY_NEXT_SUN_SETTING) + STATE_ATTRIBUTE_NEXT_SUN_SETTING) LIGHT_TRANSITION_TIME = timedelta(minutes=15) @@ -171,8 +171,10 @@ class LightTrigger(object): def _next_sun_setting(self): """ Returns the datetime object representing the next sun setting. """ + state = self.statemachine.get_state(STATE_CATEGORY_SUN) + return util.str_to_datetime( - self.statemachine.get_state(STATE_CATEGORY_NEXT_SUN_SETTING).state) + state.attributes[STATE_ATTRIBUTE_NEXT_SUN_SETTING]) def _time_for_light_before_sun_set(self): """ Helper method to calculate the point in time we have to start diff --git a/homeassistant/httpinterface.py b/homeassistant/httpinterface.py index d2a776d8df8..daaba72582f 100644 --- a/homeassistant/httpinterface.py +++ b/homeassistant/httpinterface.py @@ -110,7 +110,7 @@ class RequestHandler(BaseHTTPRequestHandler): write(("
Name | State | " - "Last Changed | Last Changed | Attributes | ")) for category in \ sorted(self.server.statemachine.categories, @@ -120,9 +120,17 @@ class RequestHandler(BaseHTTPRequestHandler): state = self.server.statemachine.get_state(category) - write("
---|---|---|---|
{} | {} | {} | |
{} | {} | {} | {} | " + "