Skip to content

Commit

Permalink
Added Hotwater Service
Browse files Browse the repository at this point in the history
  • Loading branch information
asantaga committed Feb 21, 2020
1 parent eeb7662 commit d9e550b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
21 changes: 21 additions & 0 deletions custom_components/wiser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,24 @@ async def set_smart_plug_state(self, plug_id, state):

except BaseException as e:
_LOGGER.debug("Error setting SmartPlug {} to {}, error {}".format(plug_id, state, str(e)))

async def set_hotwater_mode(self, hotwater_mode):
"""
"""
if self.wiserhub is None:
self.wiserhub = wiserHub(self.ip, self.secret)
_LOGGER.info(
"Setting Hotwater to {} ".format(hotwater_mode))
# Add small delay to allow hub to update status before refreshing
await asyncio.sleep(0.5)
await self.async_update(no_throttle=True)

try:
self.wiserhub.setHotwaterMode(hotwater_mode)


except BaseException as e:
_LOGGER.debug(
"Error setting Hotwater Mode to {}, error {}".format(hotwater_mode,
str(e)))
32 changes: 20 additions & 12 deletions custom_components/wiser/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,78 @@ boost_heating:
fields:
entity_id:
{
description: Enter the entity_id for the room required to set the boost mode.,
description: "Enter the entity_id for the room required to set the boost mode.",
example: "climate.wiser_lounge",
}
time_period:
{ description: Set the time period for the boost in minutes.,
{ description: "Set the time period for the boost in minutes.",
example: 60
}
temperature:
{
description: Set the target temperature for the boost period.,
description: "Set the target temperature for the boost period.",
example: "20.5",
}
temperature_delta:
{
description: Set the temperature increase for the boost period.,
description: "Set the temperature increase for the boost period.",
example: "2"
}
get_schedule:
description: "Read the schedule from a roomId and write to an output file in yaml"
fields:
entity_id:
{
description: Enter the entity_id for the room to read the schedule.,
description: "Enter the entity_id for the room to read the schedule.",
example: "climate.wiser_lounge",
}
filename:
{ description: The filename to write out the yaml.,
{ description: "The filename to write out the yaml.",
example: schedule1.yaml
}
set_schedule:
description: "Read in the yaml schedule file and set the schedule in a room"
fields:
entity_id:
{
description: Enter the entity_id for the room to set the schedule.,
description: "Enter the entity_id for the room to set the schedule.",
example: "climate.wiser_lounge",
}
filename:
{ description: The filename to read the yaml schedule from.,
{ description: "The filename to read the yaml schedule from.",
example: schedules/schedule1.yaml
}
copy_schedule:
description: "Copy the schedule in a room to another room"
fields:
entity_id:
{
description: Enter the entity_id for the room to copy the schedule from.,
description: "Enter the entity_id for the room to copy the schedule from.",
example: "climate.wiser_lounge",
}
to_entity_id:
{
description: Enter the entity_id for the room to copy the schedule to.,
description: "Enter the entity_id for the room to copy the schedule to.",
example: "climate.wiser_kitchen",
}
set_smartplug_mode:
description: "Sets the mode of a smart plug"
fields:
entity_id:
{
description: Enter the entity_id for the smartplug.,
description: "Enter the entity_id for the smartplug.",
example: "switch.smartplug",
}
plug_mode:
{
description: Enter the mode Auto,Manual.,
description: "Enter the mode, can be Auto or Manual.",
example: "Auto",
}
set_hotwater_mode:
description: "Sets the hot water mode"
fields:
hotwater_mode:
{
description: "Enter the mode can be on , off or manual.",
example: "auto",
}
23 changes: 23 additions & 0 deletions custom_components/wiser/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@


ATTR_PLUG_MODE="plug_mode"
ATTR_HOTWATER_MODE="hotwater_mode"

SERVICE_SET_SMARTPLUG_MODE="set_smartplug_mode"
SERVICE_SET_HOTWATER_MODE="set_hotwater_mode"


SET_PLUG_MODE_SCHEMA = vol.Schema(
{
Expand All @@ -23,6 +27,13 @@
}
)

SET_HOTWATER_MODE_SCHEMA = vol.Schema(
{

vol.Required(ATTR_HOTWATER_MODE, default="auto"): vol.Coerce(str),
}
)

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Add the Wiser System Switch entities"""
data = hass.data[DOMAIN]
Expand Down Expand Up @@ -54,9 +65,21 @@ def set_smartplug_mode(service):
smart_plug.schedule_update_ha_state(True)
break

@callback
def set_hotwater_mode(service):
hotwater_mode = service.data[ATTR_HOTWATER_MODE]
hass.async_create_task(
data.set_hotwater_mode(hotwater_mode)
)


""" Register Services """
hass.services.async_register(
DOMAIN, SERVICE_SET_SMARTPLUG_MODE, set_smartplug_mode,schema=SET_PLUG_MODE_SCHEMA,
)
hass.services.async_register(
DOMAIN, SERVICE_SET_HOTWATER_MODE, set_hotwater_mode,schema=SET_HOTWATER_MODE_SCHEMA,
)
return True

"""
Expand Down

0 comments on commit d9e550b

Please sign in to comment.