Skip to content
This repository has been archived by the owner on Mar 6, 2025. It is now read-only.

Commit

Permalink
Remove codeclimate (#26)
Browse files Browse the repository at this point in the history
* redefine all_devices.py

* purge
  • Loading branch information
ludeeus authored Dec 4, 2018
1 parent e56586a commit d2e31af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
16 changes: 0 additions & 16 deletions .codeclimate.yml

This file was deleted.

3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Build Status][travis_status]][travis]
[![PyPI version][pypi_badge]][pypi]
[![Maintainability][maintainability-badge]][maintainability-url]

_API wrapper for Google devices written in Python._

Expand Down Expand Up @@ -77,8 +76,6 @@ _This is not affiliated, associated, authorized, endorsed by, or in any way offi
[issues]: https://github.com/ludeeus/googledevices/issues
[issues-new]: https://github.com/ludeeus/googledevices/issues/new
[ludeeus]: https://github.com/ludeeus
[maintainability-badge]: https://api.codeclimate.com/v1/badges/7c88f618d3668ac24a22/maintainability
[maintainability-url]: https://codeclimate.com/github/ludeeus/googledevices/maintainability
[travis]: https://travis-ci.com/ludeeus/googledevices
[travis_status]: https://travis-ci.com/ludeeus/googledevices.svg?branch=master
[pull-request]: https://github.com/ludeeus/googledevices/compare
Expand Down
46 changes: 25 additions & 21 deletions googledevices/cli/commands/all_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ def get_all_devices(loop, subnet):
from googledevices.api.bluetooth import Bluetooth
from googledevices.utils.scan import NetworkScan
from googledevices.api.device_info import DeviceInfo
devices = {}

async def get_device_info(host):
"""Grab device information."""
async with ClientSession() as session:
googledevices = DeviceInfo(loop, session, host['host'])
await googledevices.get_device_info()
ghname = googledevices.device_info.get('name')
async with ClientSession() as session:
googledevices = Bluetooth(loop, session, host.get('host'))
await googledevices.scan_for_devices_multi_run()
await sleep(5)
await googledevices.get_scan_result()
for device in googledevices.devices:
mac = device['mac_address']
if not devices.get(mac, False):
# New device
devices[mac] = {}
devices[mac]['rssi'] = device.get('rssi')
devices[mac]['ghunit'] = ghname
elif devices[mac].get('rssi') < device.get('rssi'):
# Better RSSI value on this device
devices[mac]['rssi'] = device.get('rssi')
devices[mac]['ghunit'] = ghname

async def bluetooth_scan():
"""Get devices from all GH units on the network."""
Expand All @@ -18,31 +42,11 @@ async def bluetooth_scan():
ipscope = gateway.get(netifaces.AF_INET, ())[0][:-1] + '0/24'
else:
ipscope = subnet
devices = {}
async with ClientSession() as session:
googledevices = NetworkScan(loop, session)
result = await googledevices.scan_for_units(ipscope)
for host in result:
if host['bluetooth']:
async with ClientSession() as session:
googledevices = DeviceInfo(loop, session, host['host'])
await googledevices.get_device_info()
ghname = googledevices.device_info.get('name')
async with ClientSession() as session:
googledevices = Bluetooth(loop, session, host['host'])
await googledevices.scan_for_devices_multi_run()
await sleep(5)
await googledevices.get_scan_result()
for device in googledevices.devices:
mac = device['mac_address']
if not devices.get(mac, False):
# New device
devices[mac] = {}
devices[mac]['rssi'] = device['rssi']
devices[mac]['ghunit'] = ghname
elif devices[mac]['rssi'] < device['rssi']:
# Better RSSI value on this device
devices[mac]['rssi'] = device['rssi']
devices[mac]['ghunit'] = ghname
get_device_info(host)
print(dumps(devices, indent=4, sort_keys=True))
loop.run_until_complete(bluetooth_scan())

0 comments on commit d2e31af

Please sign in to comment.