Skip to content

Commit

Permalink
Make temperature client config values optional (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Feb 27, 2024
1 parent 732d3d3 commit 9dfbea0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions salusfy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
vol.Required(CONF_ID): cv.string,
vol.Optional(CONF_SIMULATOR, default=False): cv.boolean,
vol.Optional(CONF_ENABLE_TEMPERATURE_CLIENT, default=False): cv.boolean,
vol.Required(CONF_ENTITY_ID): cv.string,
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Optional(CONF_ENTITY_ID, default=''): cv.string,
vol.Optional(CONF_ACCESS_TOKEN, default=''): cv.string,
vol.Optional(CONF_HOST, default='localhost'): cv.string
}
)
Expand All @@ -69,10 +69,6 @@ def create_client_from(config):
password = config.get(CONF_PASSWORD)
id = config.get(CONF_ID)
enable_simulator = config.get(CONF_SIMULATOR)
enable_temperature_client = config.get(CONF_ENABLE_TEMPERATURE_CLIENT)
entity_id = config.get(CONF_ENTITY_ID)
host = config.get(CONF_HOST)
access_token = config.get(CONF_ACCESS_TOKEN)

if enable_simulator:
_LOGGER.info('Registering Salus Thermostat client simulator...')
Expand All @@ -81,11 +77,17 @@ def create_client_from(config):

web_client = WebClient(username, password, id)

enable_temperature_client = config.get(CONF_ENABLE_TEMPERATURE_CLIENT)

if not enable_temperature_client:
_LOGGER.info('Registering Salus Thermostat client...')

return web_client

entity_id = config.get(CONF_ENTITY_ID)
host = config.get(CONF_HOST)
access_token = config.get(CONF_ACCESS_TOKEN)

_LOGGER.info('Registering Salus Thermostat client with Temperature client...')

ha_client = HaTemperatureClient(host, entity_id, access_token)
Expand Down
8 changes: 6 additions & 2 deletions tests/config_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ def get(self, key):
return self._config.PASSWORD

if (key == 'simulator'):
return self._config.SIMULATOR
if hasattr(self._config, 'SIMULATOR'):
return self._config.SIMULATOR
return False

if (key == 'enable_temperature_client'):
return self._config.ENABLE_TEMPERATURE_CLIENT
if hasattr(self._config, 'ENABLE_TEMPERATURE_CLIENT'):
return self._config.ENABLE_TEMPERATURE_CLIENT
return False

if (key == 'host'):
return self._config.HOST
Expand Down

0 comments on commit 9dfbea0

Please sign in to comment.