Skip to content
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

Optional persistence in generic_thermostat #10636

Closed

Conversation

ziotibia81
Copy link
Contributor

@ziotibia81 ziotibia81 commented Nov 17, 2017

Description:

Generic thermostat can, optionally, hold target_temp and state if changed in UI

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4003

Example entry for configuration.yaml (if applicable):

- platform: generic_thermostat
  name: Test
  heater: switch.Test
  target_sensor: sensor.test
  min_temp: 4
  max_temp: 60
  target_temp: 20
  min_cycle_duration:
    seconds: 1
  keep_alive:
    minutes: 5
  cold_tolerance: 0.5
  hot_tolerance: 0.5
  persistence: both

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

if self._persistence in [ATTR_BOTH, CONF_TARGET_TEMP]:
self._target_temp=state.attributes[ATTR_TEMPERATURE]
if (self._persistence in [ATTR_BOTH, ATTR_OPERATION_MODE] and
state.attributes[ATTR_OPERATION_MODE] == STATE_OFF):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visually indented line with same indent as next logical line

if not state:
return
if self._persistence in [ATTR_BOTH, CONF_TARGET_TEMP]:
self._target_temp=state.attributes[ATTR_TEMPERATURE]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace around operator

@@ -213,6 +222,19 @@ def _async_sensor_changed(self, entity_id, old_state, new_state):
self._async_update_temp(new_state)
self._async_control_heating()
yield from self.async_update_ha_state()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace


ATTR_NONE = 'none'
ATTR_BOTH = 'both'
ATTR_OPERATION_MODE = 'operation_mode'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is available in homeassistant.components.climate

@ziotibia81 ziotibia81 changed the title Optional persistence in generi_thermostat Optional persistence in generic_thermostat Nov 17, 2017
Fix ATTR_OPERATION_MODE from homeassistant.components.climate
}})

state = hass.states.get('climate.test_thermostat')
assert(state.attributes[ATTR_TEMPERATURE] == 20)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'ATTR_TEMPERATURE'

State('climate.test_thermostat', '0', {'operation_mode': STATE_OFF}),
))

hass.state = CoreState.starting

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'CoreState'

"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('climate.test_thermostat', '0', {ATTR_TEMPERATURE: "20"}),
State('climate.test_thermostat', '0', {'operation_mode': STATE_OFF}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'State'

def test_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('climate.test_thermostat', '0', {ATTR_TEMPERATURE: "20"}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'State'
undefined name 'ATTR_TEMPERATURE'

@asyncio.coroutine
def test_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'mock_restore_cache'

}})

state = hass.states.get('climate.test_thermostat')
assert(state.attributes[ATTR_TEMPERATURE] == 20)
assert(state.attributes['operation_mode'] == STATE_OFF)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at end of file

@@ -226,6 +234,19 @@ def _async_sensor_changed(self, entity_id, old_state, new_state):
self._async_control_heating()
yield from self.async_update_ha_state()

@asyncio.coroutine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redefinition of unused 'async_added_to_hass' from line 129

@tinloaf
Copy link
Contributor

tinloaf commented Nov 17, 2017

Sorry, I think I pushed my PR literally a minute before you pushed yours. If you want, you can certainly rebase on top of the current dev branch - since my PR doesn't restore the operation mode, it would actually add functionality. However, I don't think that this should be configurable. If a user doesn't want the target temperature to be restored on startup, he / she can set the target_temperature option.

@ziotibia81
Copy link
Contributor Author

My patch work even if target_temperature is set: if there are no prevous states temperature is set from configuration.

}})

state = hass.states.get('climate.test_thermostat')
assert(state.attributes[ATTR_TEMPERATURE] == 20)
assert(state.attributes['operation_mode'] == STATE_OFF)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file
blank line contains whitespace

@tinloaf
Copy link
Contributor

tinloaf commented Nov 17, 2017

@ziotibia81 Then you should change that. 😉 The usual semantics with initial values being set in the configuration is: Restore the state only if no such value is set.

@Danielhiversen
Copy link
Member

I agree with @tinloaf, I don't think it should be configurable

@ziotibia81
Copy link
Contributor Author

Ok, but we have to restore also 'operation mode' (configurabile if restore or not, or with initial value). Before my patch at restat the state is always auto. So if user want turn off thermostat and be sure that sta off at restart he have to cange setpoint. Is more confortable to change state in off.

@tinloaf
Copy link
Contributor

tinloaf commented Nov 18, 2017

Yes, I agree, we should also restore the operation mode. And if you want to do it 100 percent, you could add an optional initial_operation_mode config, which overrides the restore value if set.

@ziotibia81
Copy link
Contributor Author

Ok! I will work on it tomorrow or Monday.

@ziotibia81
Copy link
Contributor Author

Outdated by #10690

@ziotibia81 ziotibia81 closed this Nov 20, 2017
@ziotibia81 ziotibia81 deleted the generic_thermostat_persistence branch December 5, 2017 15:01
@home-assistant home-assistant locked and limited conversation to collaborators Mar 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants