add ip address sensor
parent
cb4c54f822
commit
e19c175aef
|
@ -17,6 +17,19 @@ coloredlogs.install()
|
|||
logger = logging.getLogger("HA kiosk agent")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
def get_ip_address() -> str:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.settimeout(0)
|
||||
try:
|
||||
# doesn't even have to be reachable
|
||||
s.connect(('10.254.254.254', 1))
|
||||
IP = s.getsockname()[0]
|
||||
except Exception:
|
||||
IP = '127.0.0.1'
|
||||
finally:
|
||||
s.close()
|
||||
return IP
|
||||
|
||||
def get_temperature() -> float:
|
||||
temp = psutil.sensors_temperatures()
|
||||
if not temp or not temp['acpitz']:
|
||||
|
@ -120,6 +133,15 @@ display_brightness_info = NumberInfo(
|
|||
display_brightness_settings = Settings(mqtt=mqtt_settings, entity=display_brightness_info)
|
||||
display_brightness = Number(display_brightness_settings, display_brightness_callback)
|
||||
|
||||
# IP Address
|
||||
ip_address_info = SensorInfo(
|
||||
name="IP Address",
|
||||
device=device_info,
|
||||
unique_id=f'{args.device_id}_ip_address')
|
||||
ip_address_settings = Settings(mqtt=mqtt_settings, entity=ip_address_info)
|
||||
ip_address = Sensor(ip_address_settings)
|
||||
ip_address.set_state(get_ip_address())
|
||||
|
||||
# Temperature
|
||||
temperature_info = SensorInfo(
|
||||
name="Temperature",
|
||||
|
|
Loading…
Reference in New Issue