新規コレクター追加スキル
新しいベンダー(Linksys、Xiaomi等)のファームウェアコレクターを追加する際に使用します。
実行手順
1. ベンダー情報を確認
ユーザーに以下を確認:
- •ベンダー名(例: Linksys)
- •ファームウェアダウンロードページのURL
- •対象製品の種類(ルーター、メッシュWiFi等)
2. コレクターファイルを作成
src/ta_inspector/collector/<vendor>.py を作成:
python
"""<Vendor> router firmware collector."""
import asyncio
import logging
from typing import List, Optional
import aiohttp
from bs4 import BeautifulSoup
from .base import BaseCollector, FirmwareInfo
logger = logging.getLogger(__name__)
class <Vendor>Collector(BaseCollector):
"""Collector for <Vendor> router firmware."""
vendor_name: str = "<Vendor>"
base_url: str = "<base_url>"
def __init__(
self,
timeout: int = 30,
max_retries: int = 3,
user_agent: Optional[str] = None,
):
self.timeout = timeout
self.max_retries = max_retries
self.user_agent = user_agent or (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 Chrome/120.0.0.0"
)
self._session: Optional[aiohttp.ClientSession] = None
async def _get_session(self) -> aiohttp.ClientSession:
if self._session is None or self._session.closed:
timeout = aiohttp.ClientTimeout(total=self.timeout)
self._session = aiohttp.ClientSession(
timeout=timeout,
headers={"User-Agent": self.user_agent}
)
return self._session
async def close(self) -> None:
if self._session and not self._session.closed:
await self._session.close()
async def list_products(self) -> List[str]:
"""List available products."""
# TODO: ベンダーサイトから製品一覧を取得
return []
async def get_firmware_list(self, product: str) -> List[FirmwareInfo]:
"""Get firmware versions for a product."""
# TODO: 製品のファームウェア一覧を取得
return []
3. cli.pyに登録
src/ta_inspector/cli.py の _register_available_collectors 関数に追加:
python
from .collector.<vendor> import <Vendor>Collector auto_collector.register_collector(<Vendor>Collector())
4. テストを作成
tests/test_collector/test_<vendor>.py を作成:
python
import pytest
from ta_inspector.collector.<vendor> import <Vendor>Collector
class Test<Vendor>Collector:
@pytest.fixture
def collector(self):
return <Vendor>Collector()
@pytest.mark.asyncio
async def test_list_products(self, collector):
products = await collector.list_products()
assert isinstance(products, list)
@pytest.mark.asyncio
async def test_get_firmware_list(self, collector):
# モック対象製品でテスト
firmware_list = await collector.get_firmware_list("TestModel")
assert isinstance(firmware_list, list)
5. 確認
bash
# テスト実行 pytest tests/test_collector/test_<vendor>.py -v # リント・型チェック ruff check src/ta_inspector/collector/<vendor>.py mypy src/ta_inspector/collector/<vendor>.py
参考実装
チェックリスト
- • コレクタークラスを作成
- • list_products() を実装
- • get_firmware_list() を実装
- • cli.pyに登録
- • テストを作成
- • ruff/mypyでチェック