mirror of
https://github.com/home-assistant/android
synced 2024-09-19 08:01:31 +00:00
Remove attributes part 2 (#1035)
This commit is contained in:
parent
51072b9e0d
commit
0a2edd0467
|
@ -102,13 +102,6 @@ class AudioSensorManager : SensorManager {
|
||||||
private fun updateAudioSensor(context: Context, audioManager: AudioManager) {
|
private fun updateAudioSensor(context: Context, audioManager: AudioManager) {
|
||||||
if (!isEnabled(context, audioSensor.id))
|
if (!isEnabled(context, audioSensor.id))
|
||||||
return
|
return
|
||||||
val audioMode = when (audioManager.mode) {
|
|
||||||
AudioManager.MODE_NORMAL -> "normal"
|
|
||||||
AudioManager.MODE_RINGTONE -> "ringing"
|
|
||||||
AudioManager.MODE_IN_CALL -> "in_call"
|
|
||||||
AudioManager.MODE_IN_COMMUNICATION -> "in_communication"
|
|
||||||
else -> "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
val ringerMode = when (audioManager.ringerMode) {
|
val ringerMode = when (audioManager.ringerMode) {
|
||||||
AudioManager.RINGER_MODE_NORMAL -> "normal"
|
AudioManager.RINGER_MODE_NORMAL -> "normal"
|
||||||
|
@ -117,28 +110,6 @@ class AudioSensorManager : SensorManager {
|
||||||
else -> "unknown"
|
else -> "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
val isMicMuted = audioManager.isMicrophoneMute
|
|
||||||
|
|
||||||
val isMusicActive = audioManager.isMusicActive
|
|
||||||
|
|
||||||
val isSpeakerOn = audioManager.isSpeakerphoneOn
|
|
||||||
var isHeadphones = false
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
val audioDevices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)
|
|
||||||
for (deviceInfo in audioDevices) {
|
|
||||||
if (deviceInfo.type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES || deviceInfo.type == AudioDeviceInfo.TYPE_WIRED_HEADSET || deviceInfo.type == AudioDeviceInfo.TYPE_USB_HEADSET)
|
|
||||||
isHeadphones = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Use deprecated method as getDevices is API 23 and up only and we support API 21
|
|
||||||
isHeadphones = audioManager.isWiredHeadsetOn
|
|
||||||
}
|
|
||||||
|
|
||||||
val volumeLevelAlarm = audioManager.getStreamVolume(AudioManager.STREAM_ALARM)
|
|
||||||
val volumeLevelCall = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
|
|
||||||
val volumeLevelMusic = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
|
||||||
val volumeLevelRing = audioManager.getStreamVolume(AudioManager.STREAM_RING)
|
|
||||||
|
|
||||||
val icon = when (audioManager.ringerMode) {
|
val icon = when (audioManager.ringerMode) {
|
||||||
AudioManager.RINGER_MODE_NORMAL -> "mdi:volume-high"
|
AudioManager.RINGER_MODE_NORMAL -> "mdi:volume-high"
|
||||||
AudioManager.RINGER_MODE_SILENT -> "mdi:volume-off"
|
AudioManager.RINGER_MODE_SILENT -> "mdi:volume-off"
|
||||||
|
@ -150,17 +121,7 @@ class AudioSensorManager : SensorManager {
|
||||||
audioSensor,
|
audioSensor,
|
||||||
ringerMode,
|
ringerMode,
|
||||||
icon,
|
icon,
|
||||||
mapOf(
|
mapOf()
|
||||||
"audio_mode" to audioMode, // Remove after next release
|
|
||||||
"is_headphones" to isHeadphones, // Remove after next release
|
|
||||||
"is_mic_muted" to isMicMuted, // Remove after next release
|
|
||||||
"is_music_active" to isMusicActive, // Remove after next release
|
|
||||||
"is_speakerphone_on" to isSpeakerOn, // Remove after next release
|
|
||||||
"volume_level_alarm" to volumeLevelAlarm, // Remove after next release
|
|
||||||
"volume_level_call" to volumeLevelCall, // Remove after next release
|
|
||||||
"volume_level_music" to volumeLevelMusic, // Remove after next release
|
|
||||||
"volume_level_ring" to volumeLevelRing // Remove after next release
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,10 +128,7 @@ class BatterySensorManager : SensorManager {
|
||||||
if (!isEnabled(context, batteryState.id))
|
if (!isEnabled(context, batteryState.id))
|
||||||
return
|
return
|
||||||
|
|
||||||
val isCharging = getIsCharging(intent)
|
|
||||||
val chargerType = getChargerType(intent)
|
|
||||||
val chargingStatus = getChargingStatus(intent)
|
val chargingStatus = getChargingStatus(intent)
|
||||||
val batteryHealth = getBatteryHealth(intent)
|
|
||||||
|
|
||||||
val icon = when (chargingStatus) {
|
val icon = when (chargingStatus) {
|
||||||
"charging" -> "mdi:battery-plus"
|
"charging" -> "mdi:battery-plus"
|
||||||
|
@ -145,11 +142,7 @@ class BatterySensorManager : SensorManager {
|
||||||
batteryState,
|
batteryState,
|
||||||
chargingStatus,
|
chargingStatus,
|
||||||
icon,
|
icon,
|
||||||
mapOf(
|
mapOf()
|
||||||
"is_charging" to isCharging, // Remove after next release
|
|
||||||
"charger_type" to chargerType, // Remove after next release
|
|
||||||
"battery_health" to batteryHealth // Remove after next release
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,6 @@ class BluetoothSensorManager : SensorManager {
|
||||||
mapOf(
|
mapOf(
|
||||||
"connected_paired_devices" to connectedPairedDevices,
|
"connected_paired_devices" to connectedPairedDevices,
|
||||||
"connected_not_paired_devices" to connectedNotPairedDevices,
|
"connected_not_paired_devices" to connectedNotPairedDevices,
|
||||||
"is_bt_on" to isBtOn, // Remove after next release
|
|
||||||
"paired_devices" to bondedString
|
"paired_devices" to bondedString
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -127,39 +127,23 @@ class NetworkSensorManager : SensorManager {
|
||||||
|
|
||||||
var conInfo: WifiInfo? = null
|
var conInfo: WifiInfo? = null
|
||||||
var ssid = "Unknown"
|
var ssid = "Unknown"
|
||||||
var lastScanStrength = -1
|
|
||||||
var wifiEnabled = false
|
|
||||||
|
|
||||||
if (checkPermission(context, wifiConnection.id)) {
|
if (checkPermission(context, wifiConnection.id)) {
|
||||||
val wifiManager =
|
val wifiManager =
|
||||||
(context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager)
|
(context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager)
|
||||||
conInfo = wifiManager.connectionInfo
|
conInfo = wifiManager.connectionInfo
|
||||||
|
|
||||||
wifiEnabled = wifiManager.isWifiEnabled
|
|
||||||
|
|
||||||
ssid = if (conInfo.networkId == -1) {
|
ssid = if (conInfo.networkId == -1) {
|
||||||
"<not connected>"
|
"<not connected>"
|
||||||
} else {
|
} else {
|
||||||
conInfo.ssid.removePrefix("\"").removeSuffix("\"")
|
conInfo.ssid.removePrefix("\"").removeSuffix("\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
lastScanStrength = wifiManager.scanResults.firstOrNull {
|
|
||||||
it.BSSID == conInfo.bssid
|
|
||||||
}?.level ?: -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val icon = if (ssid != "<not connected>") "mdi:wifi" else "mdi:wifi-off"
|
val icon = if (ssid != "<not connected>") "mdi:wifi" else "mdi:wifi-off"
|
||||||
|
|
||||||
val attributes = conInfo?.let {
|
val attributes = conInfo?.let {
|
||||||
mapOf(
|
mapOf("is_hidden" to conInfo.hiddenSSID)
|
||||||
"bssid" to conInfo.bssid, // Remove after next release
|
|
||||||
"ip_address" to getIpAddress(conInfo.ipAddress), // Remove after next release
|
|
||||||
"link_speed" to conInfo.linkSpeed, // Remove after next release
|
|
||||||
"is_hidden" to conInfo.hiddenSSID,
|
|
||||||
"is_wifi_on" to wifiEnabled, // Remove after next release
|
|
||||||
"frequency" to conInfo.frequency, // Remove after next release
|
|
||||||
"signal_level" to lastScanStrength // Remove after next release
|
|
||||||
)
|
|
||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
|
|
||||||
onSensorUpdated(
|
onSensorUpdated(
|
||||||
|
|
|
@ -85,18 +85,6 @@ class StorageSensorManager : SensorManager {
|
||||||
val totalInternalStorage = getTotalInternalMemorySize()
|
val totalInternalStorage = getTotalInternalMemorySize()
|
||||||
val freeInternalStorage = getAvailableInternalMemorySize()
|
val freeInternalStorage = getAvailableInternalMemorySize()
|
||||||
val percentageFreeInternalStorage = getPercentageInternal()
|
val percentageFreeInternalStorage = getPercentageInternal()
|
||||||
externalPath = externalMemoryAvailable(context)
|
|
||||||
var totalExternalStorage = "No SD Card"
|
|
||||||
var freeExternalStorage = "No SD Card"
|
|
||||||
|
|
||||||
if (externalPath != null) {
|
|
||||||
val statSD = StatFs(externalPath.toString())
|
|
||||||
blockSizeSD = statSD.blockSizeLong
|
|
||||||
availableBlocksSD = statSD.availableBlocksLong
|
|
||||||
totalBlocksSD = statSD.blockCountLong
|
|
||||||
totalExternalStorage = getTotalExternalMemorySize()
|
|
||||||
freeExternalStorage = getAvailableExternalMemorySize()
|
|
||||||
}
|
|
||||||
|
|
||||||
val icon = "mdi:harddisk"
|
val icon = "mdi:harddisk"
|
||||||
|
|
||||||
|
@ -106,9 +94,7 @@ class StorageSensorManager : SensorManager {
|
||||||
icon,
|
icon,
|
||||||
mapOf(
|
mapOf(
|
||||||
"Free internal storage" to freeInternalStorage,
|
"Free internal storage" to freeInternalStorage,
|
||||||
"Total internal storage" to totalInternalStorage,
|
"Total internal storage" to totalInternalStorage
|
||||||
"Free external storage" to freeExternalStorage, // Remove after next release
|
|
||||||
"Total external storage" to totalExternalStorage // Remove after next release
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue