Created
June 24, 2022 22:49
-
-
Save ThinGuy/0414969fbda59efc843740348c756b95 to your computer and use it in GitHub Desktop.
Install python-kasa on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -ag KASA_PKG_LIST=(); | |
for i in python3.10-venv build-essential python3 python3-pip python3-poetry python3-cachecontrol python3-argcomplete python3-all-dev python3-wheel python3-setuptools python-all-dev python-setuptools python3.10-venv python3-virtualenv;do | |
[[ $(dpkg -l $i|awk '/'${i}'/{print $1}') = ii ]] && { true; } || { PKG_LIST+=("${i}"); }; | |
done | |
[[ ${#KASA_PKG_LIST[@]} -ge 1 ]] && { sudo apt install ${KASA_PKG_LIST[@]} -yqf --auto-remove --purge -o Acquire::ForceIPv4=true; } || { true;printf "\n\nAll package dependencies already installed\x21\n\n"; } | |
python3 -m pip install --user --upgrade pip | |
python3 -m pip install --user virtualenv | |
python3 -m pip install --user python-kasa --pre |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# vim: set et ts=2 sw=2 filetype=bash : | |
[[ $_ != $0 ]] || { printf "\n\e[2G\e[1mPlease source this script!\e[0m ( e.g. \"source ${BASH_SOURCE[0]}\" )\n\n"; sleep 1;exit; } | |
declare -ag SMART_PLUGS=$((kasa 2>&1 --type plug|awk '{if ( $4 ~ /HS103/) N=$2;if ($1 ~ /Host:/) print N,$2;next}')|xargs -rn2 -P0 bash -c 'if $(kasa --host $1|grep -qE "HS103");then echo "$0:$1";fi') | |
make-kasa-hosts-file() { | |
(kasa 2>&1 --type plug|awk '{if ( $4 ~ /HS103/) N=$2;if ($1 ~ /Host:/) print N,$2;next}')|xargs -rn2 -P0 bash -c 'if $(kasa --host $1|grep -qE "HS103");then echo $1 $0;fi' | |
};export -f make-kasa-hosts-file | |
kasa-plugs-all-off() { | |
printf '%s\n' "${SMART_PLUGS[@]//:/ }"|xargs -orn2 -P0 bash -c 'printf "Turning off smart plug $0 ($1)\n";kasa --type plug --host $1 off' | |
};export -f kasa-plugs-all-off | |
kasa-plugs-all-on() { | |
printf '%s\n' "${SMART_PLUGS[@]//:/ }"|xargs -orn2 -P0 bash -c 'printf "Turning on smart plug $0 ($1)\n";kasa --type plug --host $1 on' | |
};export -f kasa-plugs-all-on | |
kasa-plugs-all-state() { | |
printf '%s\n' "${SMART_PLUGS[@]//:/ }"|xargs -orn2 -P0 bash -c 'printf "Checking state of smart plug $0 ($1)\n";kasa --type plug --host $1 state' | |
};export -f kasa-plugs-all-state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment