mirror of https://github.com/simbaja/ha_gehome.git
- added a service to set int values (pods, delays, etc)
This commit is contained in:
parent
1cbfe63268
commit
533ae26de2
|
@ -12,4 +12,5 @@ MAX_RETRY_DELAY = 1800
|
|||
RETRY_OFFLINE_COUNT = 5
|
||||
|
||||
SERVICE_SET_TIMER = "set_timer"
|
||||
SERVICE_CLEAR_TIMER = "clear_timer"
|
||||
SERVICE_CLEAR_TIMER = "clear_timer"
|
||||
SERVICE_SET_INT_VALUE = "set_int_value"
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
from typing import Optional
|
||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT
|
||||
|
||||
|
@ -27,6 +28,8 @@ from gehomesdk import ErdCode, ErdCodeType, ErdCodeClass, ErdMeasurementUnits
|
|||
from .ge_erd_entity import GeErdEntity
|
||||
from ...devices import ApplianceApi
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
class GeErdSensor(GeErdEntity, Entity):
|
||||
"""GE Entity for sensors"""
|
||||
|
||||
|
@ -137,3 +140,10 @@ class GeErdSensor(GeErdEntity, Entity):
|
|||
if self.state.lower().endswith("closed"):
|
||||
return "mdi:door-closed"
|
||||
return super()._get_icon()
|
||||
|
||||
async def set_value(self, value):
|
||||
"""Sets the ERD value, assumes that the data type is correct"""
|
||||
try:
|
||||
await self.appliance.async_set_erd_value(self.erd_code, value)
|
||||
except:
|
||||
_LOGGER.warning(f"Could not set {self.name} to {value}")
|
|
@ -9,11 +9,17 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
|
||||
from .const import DOMAIN, SERVICE_SET_TIMER, SERVICE_CLEAR_TIMER
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
SERVICE_SET_TIMER,
|
||||
SERVICE_CLEAR_TIMER,
|
||||
SERVICE_SET_INT_VALUE
|
||||
)
|
||||
from .entities import GeErdSensor
|
||||
from .update_coordinator import GeHomeUpdateCoordinator
|
||||
|
||||
ATTR_DURATION = "duration"
|
||||
ATTR_VALUE = "value"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -51,9 +57,22 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||
},
|
||||
set_timer)
|
||||
|
||||
# register set_timer entity service
|
||||
# register clear_timer entity service
|
||||
platform.async_register_entity_service(SERVICE_CLEAR_TIMER, {}, 'clear_timer')
|
||||
|
||||
# register set_value entity service
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_INT_VALUE,
|
||||
{
|
||||
vol.Required(ATTR_VALUE): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=0)
|
||||
)
|
||||
},
|
||||
set_int_value)
|
||||
|
||||
async def set_timer(entity, service_call):
|
||||
ts = timedelta(minutes=int(service_call.data['duration']))
|
||||
await entity.set_timer(ts)
|
||||
|
||||
async def set_int_value(entity, service_call):
|
||||
await entity.set_value(int(service_call.data['value']))
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
set_timer:
|
||||
name: Set Timer
|
||||
description: Sets a GE Home timer value
|
||||
description: Sets a timer value (timespan)
|
||||
target:
|
||||
entity:
|
||||
integration: "ge_home"
|
||||
|
@ -22,8 +22,26 @@ set_timer:
|
|||
mode: slider
|
||||
clear_timer:
|
||||
name: Clear Timer
|
||||
description: Turns off a GE Home timer
|
||||
description: Clears a timer value (sets to zero)
|
||||
target:
|
||||
entity:
|
||||
integration: "ge_home"
|
||||
domain: "sensor"
|
||||
|
||||
set_int_value:
|
||||
name: Set Int Value
|
||||
description: Sets an integer value (also can be used with ERD enums)
|
||||
target:
|
||||
entity:
|
||||
integration: "ge_home"
|
||||
domain: "sensor"
|
||||
fields:
|
||||
value:
|
||||
name: Value
|
||||
description: The value to set
|
||||
required: true
|
||||
selector:
|
||||
number:
|
||||
min: 0
|
||||
max: 65535
|
||||
|
Loading…
Reference in New Issue