async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up ProgettiHWSW Automation from a config entry.""" hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = ProgettiHWSWAPI( f'{entry.data["host"]}:{entry.data["port"]}') # Check board validation again to load new values to API. await hass.data[DOMAIN][entry.entry_id].check_board() hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True
async def async_setup_entry(opp: OpenPeerPower, entry: ConfigEntry): """Set up ProgettiHWSW Automation from a config entry.""" opp.data.setdefault(DOMAIN, {}) opp.data[DOMAIN][entry.entry_id] = ProgettiHWSWAPI( f'{entry.data["host"]}:{entry.data["port"]}') # Check board validation again to load new values to API. await opp.data[DOMAIN][entry.entry_id].check_board() opp.config_entries.async_setup_platforms(entry, PLATFORMS) return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up ProgettiHWSW Automation from a config entry.""" hass.data[DOMAIN][entry.entry_id] = ProgettiHWSWAPI( f'{entry.data["host"]}:{entry.data["port"]}') # Check board validation again to load new values to API. await hass.data[DOMAIN][entry.entry_id].check_board() for component in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, component)) return True
async def validate_input(opp: core.OpenPeerPower, data): """Validate the user host input.""" api_instance = ProgettiHWSWAPI(f'{data["host"]}:{data["port"]}') is_valid = await api_instance.check_board() if not is_valid: raise CannotConnect return { "title": is_valid["title"], "relay_count": is_valid["relay_count"], "input_count": is_valid["input_count"], "is_old": is_valid["is_old"], }
async def validate_input(hass: core.HomeAssistant, data): """Validate the user host input.""" confs = hass.config_entries.async_entries(DOMAIN) same_entries = [ True for entry in confs if entry.data["host"] == data["host"] and entry.data["port"] == data["port"] ] if same_entries: raise ExistingEntry api_instance = ProgettiHWSWAPI(f'{data["host"]}:{data["port"]}') is_valid = await api_instance.check_board() if not is_valid: raise CannotConnect return { "title": is_valid["title"], "relay_count": is_valid["relay_count"], "input_count": is_valid["input_count"], "is_old": is_valid["is_old"], }
def setup_switch(api: ProgettiHWSWAPI, switch_number: int, mode: str) -> Relay: """Initialize the output pin.""" return api.get_relay(switch_number, mode)
def setup_input(api: ProgettiHWSWAPI, input_number: int) -> Input: """Initialize the input pin.""" return api.get_input(input_number)