Module plugins.hass.Configurations

Expand source code
from sys import platform

from pydantic.class_validators import validator
from modules.base.Configuration import *
from modules.base.Instances import *

#@configuration
class HassEntityConfiguration(Configuration):
    '''Exposes an action or sensor to HomeAssistant.'''

    id: str
    '''Script id to export'''

    name: Optional[str]
    '''friendly name in HomeAssistant'''

    type: str
    '''HomeAssistant type''' 

    icon: Optional[str]
    '''Icon to show in HomeAssistant'''


@configuration
class HassBinarySensorEntityConfiguration(HassEntityConfiguration):
    '''Exposes an action or sensor to HomeAssistant as a binary sensor entity.'''

    expose_state: str
    '''State to listen for ON/OFF'''

    state_topic: Optional[str]
    '''Where Homeassistant can get the state'''    

    @validator('type')
    def check_type(cls, v):
        if "sensor" not in v:
            raise ValueError("wrong type: sensor, is: " + v)
        return v          


@configuration
class HassTriggerEntityConfiguration(HassEntityConfiguration):
    '''Exposes an Action or Sensor to HomeAssistant as a trigger entity.'''

    on_command: Optional[list[AutomationConfiguration]]
    '''Automation to execute when HomeAssistant triggers ON, see `modules.base.Configuration.AutomationConfiguration`'''

    command_topic: Optional[str]
    '''Where HomeAssistant can publish the state'''

    @validator('type')
    def check_type(cls, v):
        if "trigger" not in v:
            raise ValueError("wrong type: trigger, is: " + v)
        return v      


@configuration
class HassActionEntityConfiguration(HassBinarySensorEntityConfiguration):
    '''Exposes an action or sensor to HomeAssistant as an action entity.'''

    on_command: Optional[list[AutomationConfiguration]]
    '''Automation to execute when HomeAssistant triggers ON, see `modules.base.Configuration.AutomationConfiguration`'''

    off_command: Optional[list[AutomationConfiguration]]
    '''Automation to execute when HomeAssistant triggers OFF, see `modules.base.Configuration.AutomationConfiguration`'''

    command_topic: Optional[str]
    '''Where HomeAssistant can publish the state'''

    @validator('type')
    def check_type(cls, v):
        if "switch" not in v:
            raise ValueError("wrong type: switch, is: " + v)
        return v          


@configuration
class HassPlatformConfiguration(PlatformConfiguration):
    '''Allows to export actions and sensors to HomeAssistant entities.'''

    @validator('platform')
    def check_platform(cls, v):
        if "plugins.hass" not in v:
            raise ValueError("wrong platform: plugins.hass, is: " + v)
        return v

    connection: str
    '''(MQTT) Platform used for connection to HomeAssistant'''

    exports: list[Union[HassActionEntityConfiguration, HassBinarySensorEntityConfiguration, HassTriggerEntityConfiguration]]
    '''Scripts to export to HomeAssistant'''

    auto_discovery_topic: str = "homeassistant"
    '''HomeAssistant Autodiscovery topic "homeassistant" by default'''

    base_topic: Optional[str]
    '''Base topic for entity values "home/piTomation" by default'''

Classes

class HassActionEntityConfiguration (**data: Any)

Exposes an action or sensor to HomeAssistant as an action entity.

YAML configuration

Expand source code
@configuration
class HassActionEntityConfiguration(HassBinarySensorEntityConfiguration):
    '''Exposes an action or sensor to HomeAssistant as an action entity.'''

    on_command: Optional[list[AutomationConfiguration]]
    '''Automation to execute when HomeAssistant triggers ON, see `modules.base.Configuration.AutomationConfiguration`'''

    off_command: Optional[list[AutomationConfiguration]]
    '''Automation to execute when HomeAssistant triggers OFF, see `modules.base.Configuration.AutomationConfiguration`'''

    command_topic: Optional[str]
    '''Where HomeAssistant can publish the state'''

    @validator('type')
    def check_type(cls, v):
        if "switch" not in v:
            raise ValueError("wrong type: switch, is: " + v)
        return v          

Ancestors

Class variables

var command_topic : Optional[str]

Where HomeAssistant can publish the state

var off_command : Optional[list]

Automation to execute when HomeAssistant triggers OFF, see AutomationConfiguration

var on_command : Optional[list]

Automation to execute when HomeAssistant triggers ON, see AutomationConfiguration

Static methods

def check_type(v)
Expand source code
@validator('type')
def check_type(cls, v):
    if "switch" not in v:
        raise ValueError("wrong type: switch, is: " + v)
    return v          

Inherited members

class HassBinarySensorEntityConfiguration (**data: Any)

Exposes an action or sensor to HomeAssistant as a binary sensor entity.

YAML configuration

Expand source code
@configuration
class HassBinarySensorEntityConfiguration(HassEntityConfiguration):
    '''Exposes an action or sensor to HomeAssistant as a binary sensor entity.'''

    expose_state: str
    '''State to listen for ON/OFF'''

    state_topic: Optional[str]
    '''Where Homeassistant can get the state'''    

    @validator('type')
    def check_type(cls, v):
        if "sensor" not in v:
            raise ValueError("wrong type: sensor, is: " + v)
        return v          

Ancestors

Subclasses

Class variables

var expose_state : str

State to listen for ON/OFF

var state_topic : Optional[str]

Where Homeassistant can get the state

Static methods

def check_type(v)
Expand source code
@validator('type')
def check_type(cls, v):
    if "sensor" not in v:
        raise ValueError("wrong type: sensor, is: " + v)
    return v          

Inherited members

class HassEntityConfiguration (**data: Any)

Exposes an action or sensor to HomeAssistant.

YAML configuration

Expand source code
class HassEntityConfiguration(Configuration):
    '''Exposes an action or sensor to HomeAssistant.'''

    id: str
    '''Script id to export'''

    name: Optional[str]
    '''friendly name in HomeAssistant'''

    type: str
    '''HomeAssistant type''' 

    icon: Optional[str]
    '''Icon to show in HomeAssistant'''

Ancestors

  • Configuration
  • pydantic.main.BaseModel
  • pydantic.utils.Representation

Subclasses

Class variables

var icon : Optional[str]

Icon to show in HomeAssistant

var id : str

Script id to export

var name : Optional[str]

friendly name in HomeAssistant

var type : str

HomeAssistant type

Inherited members

class HassPlatformConfiguration (**data: Any)

Allows to export actions and sensors to HomeAssistant entities.

YAML configuration

Expand source code
@configuration
class HassPlatformConfiguration(PlatformConfiguration):
    '''Allows to export actions and sensors to HomeAssistant entities.'''

    @validator('platform')
    def check_platform(cls, v):
        if "plugins.hass" not in v:
            raise ValueError("wrong platform: plugins.hass, is: " + v)
        return v

    connection: str
    '''(MQTT) Platform used for connection to HomeAssistant'''

    exports: list[Union[HassActionEntityConfiguration, HassBinarySensorEntityConfiguration, HassTriggerEntityConfiguration]]
    '''Scripts to export to HomeAssistant'''

    auto_discovery_topic: str = "homeassistant"
    '''HomeAssistant Autodiscovery topic "homeassistant" by default'''

    base_topic: Optional[str]
    '''Base topic for entity values "home/piTomation" by default'''

Ancestors

Class variables

var auto_discovery_topic : str

HomeAssistant Autodiscovery topic "homeassistant" by default

var base_topic : Optional[str]

Base topic for entity values "home/piTomation" by default

var connection : str

(MQTT) Platform used for connection to HomeAssistant

var exports : list

Scripts to export to HomeAssistant

Static methods

def check_platform(v)
Expand source code
@validator('platform')
def check_platform(cls, v):
    if "plugins.hass" not in v:
        raise ValueError("wrong platform: plugins.hass, is: " + v)
    return v

Inherited members

class HassTriggerEntityConfiguration (**data: Any)

Exposes an Action or Sensor to HomeAssistant as a trigger entity.

YAML configuration

Expand source code
@configuration
class HassTriggerEntityConfiguration(HassEntityConfiguration):
    '''Exposes an Action or Sensor to HomeAssistant as a trigger entity.'''

    on_command: Optional[list[AutomationConfiguration]]
    '''Automation to execute when HomeAssistant triggers ON, see `modules.base.Configuration.AutomationConfiguration`'''

    command_topic: Optional[str]
    '''Where HomeAssistant can publish the state'''

    @validator('type')
    def check_type(cls, v):
        if "trigger" not in v:
            raise ValueError("wrong type: trigger, is: " + v)
        return v      

Ancestors

Class variables

var command_topic : Optional[str]

Where HomeAssistant can publish the state

var on_command : Optional[list]

Automation to execute when HomeAssistant triggers ON, see AutomationConfiguration

Static methods

def check_type(v)
Expand source code
@validator('type')
def check_type(cls, v):
    if "trigger" not in v:
        raise ValueError("wrong type: trigger, is: " + v)
    return v      

Inherited members