Skip to content

Instantly share code, notes, and snippets.

@gcampax
Last active June 14, 2021 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcampax/aa3b3fe389bcce9f15ff39847e2943ed to your computer and use it in GitHub Desktop.
Save gcampax/aa3b3fe389bcce9f15ff39847e2943ed to your computer and use it in GitHub Desktop.
Quick hack to count how many distinct device types are supported by Home Assistant
import sys
import os
import re
SKIP_FILES = {
# general files
'__init__.py',
'config_flow.py',
'const.py',
'device_tracker.py',
'gateway.py',
'util.py',
'helpers.py',
'migrate.py',
'addon.py',
'entity.py',
'auth.py',
'http.py',
'common.py',
# entities we're explicitly skipping
'weather.py',
'tts.py',
'scene.py',
'notify.py'
}
KNOWN_FILES = {
'sensor.py',
'binary_sensor.py',
'cover.py',
'light.py',
'lock.py',
'switch.py',
'air_quality.py',
'media_player.py',
'climate.py',
'fan.py',
'camera.py',
'vacuum.py',
'alarm_control_panel.py',
'water_heater.py',
'media_browser.py',
'remote.py',
}
SKIP_INTEGRATIONS = {
'binary_sensor',
'sensor',
'lock',
'water_heater',
'media_extractor',
'media_player',
'media_source',
'proximity',
'remote',
'scene',
'vacuum'
'notify',
'api',
'camera',
'auth',
'blueprint',
'browser',
'fan',
'http',
'logger',
'network',
'person',
'air_quality',
'alarm_control_panel',
'cover'
}
DEVICE_CLASS_REGEXP = re.compile('DEVICE_CLASS_([A-Z_0-9]+)')
SUPPORTED_SENSORS = {
'battery',
'door',
'garage_door',
'lock',
'motion',
'humidity',
'illuminance',
'temperature',
'uv',
}
SUPPORTED_ENTITIES = {
'climate',
'cover',
'fan',
'light',
'lock',
'switch',
'vacuum'
}
def find_device_class(filename):
classes = set()
with open(filename) as fp:
for line in fp:
match = DEVICE_CLASS_REGEXP.search(line)
if match:
classes.add(match.group(1).lower())
return classes
def main():
for integration in sorted(os.listdir('./homeassistant/components')):
if integration in SKIP_INTEGRATIONS:
print(integration, 'skipped', '-', sep='\t')
continue
integrationdir = './homeassistant/components/' + integration
if not os.path.isdir(integrationdir) or \
not os.path.exists(integrationdir + '/__init__.py'):
continue
any_known = False
for filename in os.listdir(integrationdir):
if not filename.endswith('.py') or filename in SKIP_FILES:
continue
if filename in KNOWN_FILES:
any_known = True
if filename in ('sensor.py', 'binary_sensor.py'):
any_known_sensor = False
for device_class in find_device_class(os.path.join(integrationdir, filename)):
print(integration, filename[:-3], device_class, 'supported' if device_class in SUPPORTED_SENSORS else 'unsupported', sep='\t')
any_known_sensor = True
if not any_known_sensor:
print(integration, filename[:-3], 'unknown', 'unsupported', sep='\t')
else:
print(integration, filename[:-3], '-', 'supported' if filename[:-3] in SUPPORTED_ENTITIES else 'unsupported', sep='\t')
else:
#print(f'Ignored file {filename} in {integration}', file=sys.stderr)
pass
if not any_known:
print(f'Did not recognize integration {integration}', file=sys.stderr)
print(integration, 'unknown', '-', 'unsupported', sep='\t')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment