Skip to content

Commit

Permalink
Merge pull request #353 from danieldotnl/sep_http
Browse files Browse the repository at this point in the history
Separate http settings for form submit and scrape request
  • Loading branch information
danieldotnl authored Apr 5, 2024
2 parents 3efd918 + df6d19c commit 89a013d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion custom_components/multiscrape/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ async def _async_process_config(hass: HomeAssistant, config) -> bool:
form_submit_config = conf.get(CONF_FORM_SUBMIT)
form_submitter = None
if form_submit_config:
form_http = create_http_wrapper(config_name, form_submit_config, hass, file_manager)
parser = conf.get(CONF_PARSER)
form_submitter = create_form_submitter(
config_name, form_submit_config, hass, http, file_manager, parser
config_name, form_submit_config, hass, form_http, file_manager, parser
)

scraper = create_scraper(config_name, conf, hass, file_manager)
Expand Down
1 change: 0 additions & 1 deletion custom_components/multiscrape/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
CONF_FORM_SELECT = "select"
CONF_FORM_INPUT = "input"
CONF_FORM_INPUT_FILTER = "input_filter"
CONF_FORM_RESOURCE = "resource"
CONF_FORM_SUBMIT_ONCE = "submit_once"
CONF_FORM_RESUBMIT_ERROR = "resubmit_on_error"
CONF_LOG_RESPONSE = "log_response"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/multiscrape/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from bs4 import BeautifulSoup

from homeassistant.core import HomeAssistant
from homeassistant.const import CONF_RESOURCE

from .const import (
CONF_FORM_RESOURCE,
CONF_FORM_SELECT,
CONF_FORM_INPUT,
CONF_FORM_INPUT_FILTER,
Expand All @@ -23,7 +23,7 @@

def create_form_submitter(config_name, config, hass, http, file_manager, parser):
"""Create a form submitter instance."""
resource = config.get(CONF_FORM_RESOURCE)
resource = config.get(CONF_RESOURCE)
select = config.get(CONF_FORM_SELECT)
input_values = config.get(CONF_FORM_INPUT)
input_filter = config.get(CONF_FORM_INPUT_FILTER)
Expand Down
25 changes: 14 additions & 11 deletions custom_components/multiscrape/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from .const import CONF_ATTR
from .const import CONF_FORM_INPUT
from .const import CONF_FORM_INPUT_FILTER
from .const import CONF_FORM_RESOURCE
from .const import CONF_FORM_RESUBMIT_ERROR
from .const import CONF_FORM_SELECT
from .const import CONF_FORM_SUBMIT
Expand Down Expand Up @@ -75,16 +74,7 @@

_LOGGER = logging.getLogger(__name__)

FORM_SUBMIT_SCHEMA = {
vol.Optional(CONF_FORM_RESOURCE): cv.string,
vol.Optional(CONF_FORM_SELECT): cv.string,
vol.Optional(CONF_FORM_INPUT): vol.Schema({cv.string: cv.string}),
vol.Optional(CONF_FORM_INPUT_FILTER, default=[]): cv.ensure_list,
vol.Optional(CONF_FORM_SUBMIT_ONCE, default=False): cv.boolean,
vol.Optional(CONF_FORM_RESUBMIT_ERROR, default=True): cv.boolean,
}

INTEGRATION_SCHEMA = {
HTTP_SCHEMA = {
vol.Exclusive(CONF_RESOURCE, CONF_RESOURCE): cv.url,
vol.Exclusive(CONF_RESOURCE_TEMPLATE, CONF_RESOURCE): cv.template,
vol.Optional(CONF_AUTHENTICATION): vol.In(
Expand All @@ -98,6 +88,19 @@
vol.Optional(CONF_PAYLOAD): cv.template,
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
}

FORM_SUBMIT_SCHEMA = {
**HTTP_SCHEMA,
vol.Optional(CONF_FORM_SELECT): cv.string,
vol.Optional(CONF_FORM_INPUT): vol.Schema({cv.string: cv.string}),
vol.Optional(CONF_FORM_INPUT_FILTER, default=[]): cv.ensure_list,
vol.Optional(CONF_FORM_SUBMIT_ONCE, default=False): cv.boolean,
vol.Optional(CONF_FORM_RESUBMIT_ERROR, default=True): cv.boolean,
}

INTEGRATION_SCHEMA = {
**HTTP_SCHEMA,
vol.Optional(CONF_PARSER, default=DEFAULT_PARSER): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_SCAN_INTERVAL): cv.time_period,
Expand Down
3 changes: 2 additions & 1 deletion custom_components/multiscrape/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ async def _prepare_service_request(hass: HomeAssistant, conf, config_name):
form_submit_config = conf.get(CONF_FORM_SUBMIT)
parser = conf.get(CONF_PARSER)
if form_submit_config:
form_http = create_http_wrapper(config_name, form_submit_config, hass, None)
form_submitter = create_form_submitter(
config_name, form_submit_config, hass, http, None, parser
config_name, form_submit_config, hass, form_http, None, parser
)
request_manager = create_content_request_manager(
config_name, conf, hass, http, form_submitter
Expand Down

0 comments on commit 89a013d

Please # to comment.