<s> """<STR_LIT>""" <EOL> import os <EOL> import logging <EOL> import voluptuous as vol <EOL> from homeassistant . config import load_yaml_config_file <EOL> from homeassistant . helpers . entity_component import EntityComponent <EOL> from homeassistant . helpers . entity import Entity <EOL> from homeassistant . helpers . config_validation import PLATFORM_SCHEMA <EOL> import homeassistant . helpers . config_validation as cv <EOL> from homeassistant . components import group <EOL> from homeassistant . const import ( <EOL> SERVICE_MOVE_UP , SERVICE_MOVE_DOWN , SERVICE_STOP , <EOL> STATE_OPEN , STATE_CLOSED , STATE_UNKNOWN , ATTR_ENTITY_ID ) <EOL> DOMAIN = '<STR_LIT>' <EOL> SCAN_INTERVAL = <NUM_LIT:15> <EOL> GROUP_NAME_ALL_ROLLERSHUTTERS = '<STR_LIT>' <EOL> ENTITY_ID_ALL_ROLLERSHUTTERS = group . ENTITY_ID_FORMAT . format ( <EOL> '<STR_LIT>' ) <EOL> ENTITY_ID_FORMAT = DOMAIN + '<STR_LIT>' <EOL> DISCOVERY_PLATFORMS = { } <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> ATTR_CURRENT_POSITION = '<STR_LIT>' <EOL> ROLLERSHUTTER_SERVICE_SCHEMA = vol . Schema ( { <EOL> vol . Optional ( ATTR_ENTITY_ID ) : cv . entity_ids , <EOL> } ) <EOL> def is_open ( hass , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> entity_id = entity_id or ENTITY_ID_ALL_ROLLERSHUTTERS <EOL> return hass . states . is_state ( entity_id , STATE_OPEN ) <EOL> def move_up ( hass , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { ATTR_ENTITY_ID : entity_id } if entity_id else None <EOL> hass . services . call ( DOMAIN , SERVICE_MOVE_UP , data ) <EOL> def move_down ( hass , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { ATTR_ENTITY_ID : entity_id } if entity_id else None <EOL> hass . services . call ( DOMAIN , SERVICE_MOVE_DOWN , data ) <EOL> def stop ( hass , entity_id = None ) : <EOL> """<STR_LIT>""" <EOL> data = { ATTR_ENTITY_ID : entity_id } if entity_id else None <EOL> hass . services . call ( DOMAIN , SERVICE_STOP , data ) <EOL> def setup ( hass , config ) : <EOL> """<STR_LIT>""" <EOL> component = EntityComponent ( <EOL> _LOGGER , DOMAIN , hass , SCAN_INTERVAL , DISCOVERY_PLATFORMS , <EOL> GROUP_NAME_ALL_ROLLERSHUTTERS ) <EOL> component . setup ( config ) <EOL> def handle_rollershutter_service ( service ) : <EOL> """<STR_LIT>""" <EOL> target_rollershutters = component . extract_from_service ( service ) <EOL> for rollershutter in target_rollershutters : <EOL> if service . service == SERVICE_MOVE_UP : <EOL> rollershutter . move_up ( ) <EOL> elif service . service == SERVICE_MOVE_DOWN : <EOL> rollershutter . move_down ( ) <EOL> elif service . service == SERVICE_STOP : <EOL> rollershutter . stop ( ) <EOL> if rollershutter . should_poll : <EOL> rollershutter . update_ha_state ( True ) <EOL> descriptions = load_yaml_config_file ( <EOL> os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> hass . services . register ( DOMAIN , SERVICE_MOVE_UP , <EOL> handle_rollershutter_service , <EOL> descriptions . get ( SERVICE_MOVE_UP ) , <EOL> schema = ROLLERSHUTTER_SERVICE_SCHEMA ) <EOL> hass . services . register ( DOMAIN , SERVICE_MOVE_DOWN , <EOL> handle_rollershutter_service , <EOL> descriptions . get ( SERVICE_MOVE_DOWN ) , <EOL> schema = ROLLERSHUTTER_SERVICE_SCHEMA ) <EOL> hass . services . register ( DOMAIN , SERVICE_STOP , <EOL> handle_rollershutter_service , <EOL> descriptions . get ( SERVICE_STOP ) , <EOL> schema = ROLLERSHUTTER_SERVICE_SCHEMA ) <EOL> return True <EOL> class RollershutterDevice ( Entity ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def current_position ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ property <EOL> def state ( self ) : <EOL> """<STR_LIT>""" <EOL> current = self . current_position <EOL> if current is None : <EOL> return STATE_UNKNOWN <EOL> return STATE_CLOSED if current == <NUM_LIT:0> else STATE_OPEN <EOL> @ property <EOL> def state_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> current = self . current_position <EOL> if current is None : <EOL> return None <EOL> return { <EOL> ATTR_CURRENT_POSITION : current <EOL> } <EOL> def move_up ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def move_down ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def stop ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
