mirror of
https://github.com/fmtr/haco.git
synced 2026-10-26 10:51:46 -04:00
Set default capability name and fix typing
This commit is contained in:
parent
85638bc339
commit
470734c6a3
7 changed files with 21 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from haco import schema, constants
|
||||
from haco import schema
|
||||
from haco.control import Control
|
||||
|
||||
|
||||
|
|
@ -10,9 +10,8 @@ class Button(Control):
|
|||
return schema.Schema(
|
||||
capabilities=[
|
||||
schema.Capability(
|
||||
name=constants.DEFAULT,
|
||||
ha=schema.HomeAssistant(announce_data=schema.AnnounceTopic(key='{io_ha}_topic')),
|
||||
tamota=None
|
||||
tasmota=None
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -41,18 +41,18 @@ class Climate(Control):
|
|||
Capability(
|
||||
name='current_humidity',
|
||||
ha=None,
|
||||
tamota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
tasmota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
),
|
||||
Capability(
|
||||
name='current_temperature',
|
||||
ha=None,
|
||||
tamota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
tasmota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
),
|
||||
Capability(
|
||||
name='action',
|
||||
type=str,
|
||||
ha=None,
|
||||
tamota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
tasmota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ CHARS_ALLOWED = string.ascii_lowercase + string.digits
|
|||
SEPS = '_- /'
|
||||
BRANCH = 'release'
|
||||
|
||||
DEFAULT = 'default'
|
||||
CAPABILITY_DEFAULT = 'default'
|
||||
|
||||
CONFIGS_PATH = Path(os.environ['HACO_CONFIGS_PATH'])
|
||||
OPTIONS_PATH = Path(os.environ['HACO_OPTIONS_PATH'])
|
||||
|
|
|
|||
|
|
@ -17,9 +17,8 @@ class Control:
|
|||
schema = Schema(
|
||||
capabilities=[
|
||||
Capability(
|
||||
name=constants.DEFAULT,
|
||||
ha=HomeAssistant(announce_data=AnnounceTopic(key='{io_ha}_topic')),
|
||||
tamota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic'))
|
||||
tasmota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic'))
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
@ -49,7 +48,7 @@ class Control:
|
|||
def add_callback(self, trigger, function):
|
||||
|
||||
if (function_name := function.__name__) in {Tasmota.PLATFORM, HomeAssistant.PLATFORM}:
|
||||
function_name = f'{constants.DEFAULT}_{function_name}'
|
||||
function_name = f'{constants.CAPABILITY_DEFAULT}_{function_name}'
|
||||
|
||||
callback_names = self.schema.get_callback_function_names()
|
||||
|
||||
|
|
|
|||
|
|
@ -313,13 +313,20 @@ class Default:
|
|||
|
||||
class Capability:
|
||||
|
||||
def __init__(self, name, type=ControlType, tamota: Tasmota = Default, ha: HomeAssistant = Default, alias=None):
|
||||
def __init__(
|
||||
self,
|
||||
name: str = constants.CAPABILITY_DEFAULT,
|
||||
type=ControlType,
|
||||
tasmota: typing.Optional[Tasmota] = Default,
|
||||
ha: typing.Optional[HomeAssistant] = Default,
|
||||
alias: typing.Optional[str] = None
|
||||
):
|
||||
self.name = name
|
||||
self.alias = alias or name
|
||||
self.type = type
|
||||
self.schema = None
|
||||
|
||||
self.tasmota = tamota if tamota is not Default else Tasmota()
|
||||
self.tasmota = tasmota if tasmota is not Default else Tasmota()
|
||||
self.ha = ha if ha is not Default else HomeAssistant()
|
||||
self.platforms = [io for io in {self.tasmota, self.ha} if io]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from haco import schema, constants
|
||||
from haco import schema
|
||||
from haco.control import Control
|
||||
from haco.data.type_sensor import DeviceClassSensor
|
||||
|
||||
|
|
@ -16,9 +16,8 @@ class Sensor(Control):
|
|||
return schema.Schema(
|
||||
capabilities=[
|
||||
schema.Capability(
|
||||
name=constants.DEFAULT,
|
||||
ha=None,
|
||||
tamota=schema.Tasmota(announce_data=schema.AnnounceTopic(key='{io_ha}_topic'))
|
||||
tasmota=schema.Tasmota(announce_data=schema.AnnounceTopic(key='{io_ha}_topic'))
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from haco import constants
|
||||
from haco.control import Control
|
||||
from haco.schema import Schema, Capability, AnnounceTopic, Tasmota, HomeAssistant
|
||||
|
||||
|
|
@ -11,14 +10,13 @@ class Update(Control):
|
|||
schema = Schema(
|
||||
capabilities=[
|
||||
Capability(
|
||||
name=constants.DEFAULT,
|
||||
ha=HomeAssistant(announce_data=AnnounceTopic(key='{io_ha}_topic')),
|
||||
tamota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic'))
|
||||
tasmota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic'))
|
||||
),
|
||||
Capability(
|
||||
name='latest_version',
|
||||
ha=None,
|
||||
tamota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
tasmota=Tasmota(announce_data=AnnounceTopic(key='{capability}_topic'))
|
||||
)
|
||||
]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue