『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 4660|回复: 1

[已解决] 开发自定义插件问题

[复制链接]

13

主题

151

帖子

542

积分

论坛积极会员

积分
542
金钱
391
HASS币
0
发表于 2018-7-6 16:37:08 | 显示全部楼层 |阅读模式
本帖最后由 afusky 于 2018-7-12 15:40 编辑

参考论坛上大神写的自动下载插件,自己学习写了个插件,但是在配置的时候点击检查配置,一直报错,请问什么原因
moviedownload:
  website: 'http://gaoqing.fm/'
  listurl: '/?sort=最新&country=&director=&actor=&type=&year='
  savepath: '/config/transmission-watchdir'


检查配置提示错误如下:
Invalid config for [moviedownload]: required key not provided @ data['platform']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/moviedownload/



代码如下
import xxx

uaList = [{'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'},
          {'User-Agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'},
          {'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'}]
rd = random.randint(0, len(uaList) - 1)
ua = uaList[rd]

_LOGGER = logging.getLogger(__name__)
CONF_WEBSITE = 'website'
CONF_LIST_URL = 'listurl'
CONF_SAVE_PATH = 'savepath'
DOMAIN = 'moviedownload'
ADD_COUNT=0

SERVICE_DOWNLOAD = 'Download'
SERVICE_DOWNLOAD_SCHEMA = vol.Schema({
    vol.Required(CONF_WEBSITE): cv.string,
    vol.Required(CONF_LIST_URL): cv.string,
    vol.Required(CONF_SAVE_PATH): cv.string,
}, extra=vol.ALLOW_EXTRA)

CONFIG_SCHEMA = vol.Schema({
    DOMAIN: vol.Schema({
        vol.Required(CONF_WEBSITE): cv.string,
        vol.Required(CONF_LIST_URL): cv.string,
        vol.Required(CONF_SAVE_PATH): cv.string,
    })
}, extra=vol.ALLOW_EXTRA)

def setup(hass, config):

    website = config[DOMAIN][CONF_WEBSITE]
    list_url = config[DOMAIN][CONF_LIST_URL]
    save_path = config[DOMAIN][CONF_SAVE_PATH]

    if website == None:
        _LOGGER.error('moviedownload:website is null' )

    if list_url == None:
        _LOGGER.error('moviedownload:list_url is null' )

    if save_path == None:
        _LOGGER.error('moviedownload:save_path is null' )

    _LOGGER.info('>>>>>>>>>>>>>>>>>>moviedownload:paras is ok')

    def down_movie_torrent(url, t_file_path):
        global ADD_COUNT
        data = requests.get(url, headers=ua).text
        soup = bs4.BeautifulSoup(data, "html.parser")
        a_torrent = soup.find_all('a')
        dict = {}
            #下载具体逻辑
return
    def moviedownload_download(service):
        _LOGGER.info('>>>>>>>>>>>>>>>> start moviedownload:'+website + list_url+',save_path:'+save_path)
        threading.Thread(target=down_movie_torrent(website + list_url, save_path)).start()
    hass.services.register(DOMAIN, SERVICE_DOWNLOAD, moviedownload_download,schema=SERVICE_DOWNLOAD_SCHEMA)
    return True

回复

使用道具 举报

13

主题

151

帖子

542

积分

论坛积极会员

积分
542
金钱
391
HASS币
0
 楼主| 发表于 2018-7-12 15:40:58 | 显示全部楼层
自己解决了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-23 21:07 , Processed in 0.221075 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表