1 """Sensor for displaying the number of result on Shodan.io."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
21 _LOGGER = logging.getLogger(__name__)
25 DEFAULT_NAME =
"Shodan Sensor"
29 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
31 vol.Required(CONF_API_KEY): cv.string,
32 vol.Required(CONF_QUERY): cv.string,
33 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
41 add_entities: AddEntitiesCallback,
42 discovery_info: DiscoveryInfoType |
None =
None,
44 """Set up the Shodan sensor."""
45 api_key = config[CONF_API_KEY]
46 name = config[CONF_NAME]
47 query = config[CONF_QUERY]
49 data =
ShodanData(shodan.Shodan(api_key), query)
52 except shodan.exception.APIError
as error:
53 _LOGGER.warning(
"Unable to connect to Shodan.io: %s", error)
60 """Representation of the Shodan sensor."""
62 _attr_attribution =
"Data provided by Shodan"
63 _attr_icon =
"mdi:tooltip-text"
64 _attr_native_unit_of_measurement =
"Hits"
66 def __init__(self, data: ShodanData, name: str) ->
None:
67 """Initialize the Shodan sensor."""
72 """Get the latest data and updates the states."""
78 """Get the latest data and update the states."""
80 def __init__(self, api: shodan.Shodan, query: str) ->
None:
81 """Initialize the data object."""
86 """Get the latest data from shodan.io."""
None __init__(self, shodan.Shodan api, str query)
None __init__(self, ShodanData data, str name)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)