Split up external storage to its own sensor, part 1 (#902)

* Split up external storage to its own sensor, part 1

* Lint

* Add note to remove attributes after the next release
This commit is contained in:
Daniel Shokouhi 2020-09-08 13:13:50 -07:00 committed by GitHub
parent 88ce628cec
commit 10c5769349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 12 deletions

View file

@ -15,8 +15,15 @@ class StorageSensorManager : SensorManager {
private val storageSensor = SensorManager.BasicSensor( private val storageSensor = SensorManager.BasicSensor(
"storage_sensor", "storage_sensor",
"sensor", "sensor",
R.string.sensor_name_storage, R.string.basic_sensor_name_internal_storage,
R.string.sensor_description_storage_sensor, R.string.sensor_description_internal_storage,
unitOfMeasurement = "%"
)
private val externalStorage = SensorManager.BasicSensor(
"external_storage",
"sensor",
R.string.basic_sensor_name_external_storage,
R.string.sensor_description_external_storage,
unitOfMeasurement = "%" unitOfMeasurement = "%"
) )
val path: File = Environment.getDataDirectory() val path: File = Environment.getDataDirectory()
@ -58,7 +65,7 @@ class StorageSensorManager : SensorManager {
override val name: Int override val name: Int
get() = R.string.sensor_name_storage get() = R.string.sensor_name_storage
override val availableSensors: List<SensorManager.BasicSensor> override val availableSensors: List<SensorManager.BasicSensor>
get() = listOf(storageSensor) get() = listOf(storageSensor, externalStorage)
override fun requiredPermissions(): Array<String> { override fun requiredPermissions(): Array<String> {
return emptyArray() return emptyArray()
@ -68,6 +75,7 @@ class StorageSensorManager : SensorManager {
context: Context context: Context
) { ) {
updateStorageSensor(context) updateStorageSensor(context)
updateExternalStorageSensor(context)
} }
private fun updateStorageSensor(context: Context) { private fun updateStorageSensor(context: Context) {
@ -99,8 +107,40 @@ class StorageSensorManager : SensorManager {
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, "Free external storage" to freeExternalStorage, // Remove after next release
"Total external storage" to totalExternalStorage "Total external storage" to totalExternalStorage // Remove after next release
)
)
}
private fun updateExternalStorageSensor(context: Context) {
if (!isEnabled(context, externalStorage.id))
return
externalPath = externalMemoryAvailable(context)
var totalExternalStorage = "No SD Card"
var freeExternalStorage = "No SD Card"
var percentFreeExternal = 0
if (externalPath != null) {
val statSD = StatFs(externalPath.toString())
blockSizeSD = statSD.blockSizeLong
availableBlocksSD = statSD.availableBlocksLong
totalBlocksSD = statSD.blockCountLong
totalExternalStorage = getTotalExternalMemorySize()
freeExternalStorage = getAvailableExternalMemorySize()
percentFreeExternal = ((availableBlocksSD.toDouble() / totalBlocksSD.toDouble()) * 100).roundToInt()
}
val icon = "mdi:micro-sd"
onSensorUpdated(context,
externalStorage,
percentFreeExternal,
icon,
mapOf(
"free_external_storage" to freeExternalStorage,
"total_external_storage" to totalExternalStorage
) )
) )
} }

View file

@ -144,7 +144,7 @@ instancia de Home Assistant</string>
<string name="sensor_description_sim_1">Información sobre el proveedor de telefonía móvil actual en la ranura SIM 1</string> <string name="sensor_description_sim_1">Información sobre el proveedor de telefonía móvil actual en la ranura SIM 1</string>
<string name="sensor_description_sim_2">Información sobre el proveedor de telefonía móvil actual en la ranura SIM 2</string> <string name="sensor_description_sim_2">Información sobre el proveedor de telefonía móvil actual en la ranura SIM 2</string>
<string name="sensor_description_steps_sensor">El número total de pasos desde el último reinicio del dispositivo</string> <string name="sensor_description_steps_sensor">El número total de pasos desde el último reinicio del dispositivo</string>
<string name="sensor_description_storage_sensor">Información sobre el espacio de almacenamiento total y disponible interno y externo</string> <string name="sensor_description_internal_storage">Información sobre el espacio de almacenamiento total y disponible interno y externo</string>
<string name="sensor_description_wifi_connection">Información sobre la red WiFi conectada actualmente</string> <string name="sensor_description_wifi_connection">Información sobre la red WiFi conectada actualmente</string>
<string name="sensor_summary">Usa esto para controlar qué sensores están activados/desactivados.</string> <string name="sensor_summary">Usa esto para controlar qué sensores están activados/desactivados.</string>
<string name="sensor_title">Administrar sensores</string> <string name="sensor_title">Administrar sensores</string>

View file

@ -147,7 +147,7 @@ Scansione della rete</string>
<string name="sensor_description_sim_1">Informazioni sul provider di telefonia mobile corrente nello slot SIM 1</string> <string name="sensor_description_sim_1">Informazioni sul provider di telefonia mobile corrente nello slot SIM 1</string>
<string name="sensor_description_sim_2">Informazioni sul provider di telefonia mobile corrente nello slot SIM 2</string> <string name="sensor_description_sim_2">Informazioni sul provider di telefonia mobile corrente nello slot SIM 2</string>
<string name="sensor_description_steps_sensor">Il numero totale di passi dall\'ultimo riavvio del dispositivo</string> <string name="sensor_description_steps_sensor">Il numero totale di passi dall\'ultimo riavvio del dispositivo</string>
<string name="sensor_description_storage_sensor">Informazioni sullo spazio di archiviazione totale e disponibile internamente ed esternamente</string> <string name="sensor_description_internal_storage">Informazioni sullo spazio di archiviazione totale e disponibile internamente ed esternamente</string>
<string name="sensor_description_wifi_connection">Informazioni sulla rete WiFi attualmente connessa</string> <string name="sensor_description_wifi_connection">Informazioni sulla rete WiFi attualmente connessa</string>
<string name="sensor_summary">Consente di gestire i sensori abilitati/disabilitati.</string> <string name="sensor_summary">Consente di gestire i sensori abilitati/disabilitati.</string>
<string name="sensor_title">Gestione dei sensori</string> <string name="sensor_title">Gestione dei sensori</string>

View file

@ -117,7 +117,7 @@
<string name="security">Bezpieczeństwo</string> <string name="security">Bezpieczeństwo</string>
<string name="select_entity_to_display">Wybierz encję do wyświetlenia</string> <string name="select_entity_to_display">Wybierz encję do wyświetlenia</string>
<string name="select_instance">Wybierz instancję, z którą chcesz się połączyć:</string> <string name="select_instance">Wybierz instancję, z którą chcesz się połączyć:</string>
<string name="sensor_description_storage_sensor">Informacje o całkowitej i dostępnej przestrzeni dysku wewnętrznego i karty pamięci</string> <string name="sensor_description_internal_storage">Informacje o całkowitej i dostępnej przestrzeni dysku wewnętrznego i karty pamięci</string>
<string name="sensor_description_wifi_connection">Informacje o aktualnie podłączonej sieci WiFi</string> <string name="sensor_description_wifi_connection">Informacje o aktualnie podłączonej sieci WiFi</string>
<string name="sensor_summary">Użyj tego, aby włączyć/wyłączyć sensory</string> <string name="sensor_summary">Użyj tego, aby włączyć/wyłączyć sensory</string>
<string name="sensor_title">Zarządzaj sensorami</string> <string name="sensor_title">Zarządzaj sensorami</string>

View file

@ -144,7 +144,7 @@
<string name="sensor_description_sim_1">Информация об операторе сотовой связи в слоте SIM 1</string> <string name="sensor_description_sim_1">Информация об операторе сотовой связи в слоте SIM 1</string>
<string name="sensor_description_sim_2">Информация об операторе сотовой связи в слоте SIM 2</string> <string name="sensor_description_sim_2">Информация об операторе сотовой связи в слоте SIM 2</string>
<string name="sensor_description_steps_sensor">Общее количество шагов с момента последней перезагрузки устройства</string> <string name="sensor_description_steps_sensor">Общее количество шагов с момента последней перезагрузки устройства</string>
<string name="sensor_description_storage_sensor">Информация о внутреннем и внешнем пространстве для хранения</string> <string name="sensor_description_internal_storage">Информация о внутреннем и внешнем пространстве для хранения</string>
<string name="sensor_description_wifi_connection">Информация о сети Wi-Fi, к которой подключено устройство</string> <string name="sensor_description_wifi_connection">Информация о сети Wi-Fi, к которой подключено устройство</string>
<string name="sensor_summary">Включение или отключение сенсоров мобильного приложения</string> <string name="sensor_summary">Включение или отключение сенсоров мобильного приложения</string>
<string name="sensor_title">Управление сенсорами</string> <string name="sensor_title">Управление сенсорами</string>

View file

@ -146,7 +146,7 @@ Home Assistant实例</string>
<string name="sensor_description_sim_1">SIM插槽1中有关当前蜂窝电话提供商的信息</string> <string name="sensor_description_sim_1">SIM插槽1中有关当前蜂窝电话提供商的信息</string>
<string name="sensor_description_sim_2">SIM插槽2中有关当前蜂窝电话提供商的信息</string> <string name="sensor_description_sim_2">SIM插槽2中有关当前蜂窝电话提供商的信息</string>
<string name="sensor_description_steps_sensor">自上次重新启动设备以来的总步数</string> <string name="sensor_description_steps_sensor">自上次重新启动设备以来的总步数</string>
<string name="sensor_description_storage_sensor">有关内部和外部总可用存储空间的信息</string> <string name="sensor_description_internal_storage">有关内部和外部总可用存储空间的信息</string>
<string name="sensor_description_wifi_connection">有关当前连接的WiFi网络的信息</string> <string name="sensor_description_wifi_connection">有关当前连接的WiFi网络的信息</string>
<string name="sensor_summary">使用它来管理启用/禁用的传感器。</string> <string name="sensor_summary">使用它来管理启用/禁用的传感器。</string>
<string name="sensor_title">管理传感器</string> <string name="sensor_title">管理传感器</string>

View file

@ -161,6 +161,8 @@ like to connect to:</string>
<string name="sensor_description_charger_type">The type of charger plugged into the device currently</string> <string name="sensor_description_charger_type">The type of charger plugged into the device currently</string>
<string name="sensor_description_battery_health">The health of the battery</string> <string name="sensor_description_battery_health">The health of the battery</string>
<string name="sensor_name_power">Power Sensors</string> <string name="sensor_name_power">Power Sensors</string>
<string name="basic_sensor_name_internal_storage">Internal Storage</string>
<string name="basic_sensor_name_external_storage">External Storage</string>
<string name="basic_sensor_name_power_save">Power Save</string> <string name="basic_sensor_name_power_save">Power Save</string>
<string name="basic_sensor_name_interactive">Interactive</string> <string name="basic_sensor_name_interactive">Interactive</string>
<string name="basic_sensor_name_doze">Doze Mode</string> <string name="basic_sensor_name_doze">Doze Mode</string>
@ -195,14 +197,15 @@ like to connect to:</string>
<string name="sensor_name_pressure">Pressure Sensor</string> <string name="sensor_name_pressure">Pressure Sensor</string>
<string name="sensor_name_proximity">Proximity Sensor</string> <string name="sensor_name_proximity">Proximity Sensor</string>
<string name="sensor_name_steps">Steps Sensor</string> <string name="sensor_name_steps">Steps Sensor</string>
<string name="sensor_name_storage">Storage Sensor</string> <string name="sensor_name_storage">Storage Sensors</string>
<string name="sensor_description_phone_state">Whether or not the phone is ringing or in a call, no other caller information is stored</string> <string name="sensor_description_phone_state">Whether or not the phone is ringing or in a call, no other caller information is stored</string>
<string name="sensor_description_pressure_sensor">The current ambient air pressure reading</string> <string name="sensor_description_pressure_sensor">The current ambient air pressure reading</string>
<string name="sensor_description_proximity_sensor">The current proximity reading, some devices only report near or far</string> <string name="sensor_description_proximity_sensor">The current proximity reading, some devices only report near or far</string>
<string name="sensor_description_sim_1">Information about the current cellular provider in SIM slot 1</string> <string name="sensor_description_sim_1">Information about the current cellular provider in SIM slot 1</string>
<string name="sensor_description_sim_2">Information about the current cellular provider in SIM slot 2</string> <string name="sensor_description_sim_2">Information about the current cellular provider in SIM slot 2</string>
<string name="sensor_description_steps_sensor">The total number of steps since the last reboot of the device</string> <string name="sensor_description_steps_sensor">The total number of steps since the last reboot of the device</string>
<string name="sensor_description_storage_sensor">Information about the total and available storage space internally and externally</string> <string name="sensor_description_internal_storage">Information about the total and available storage space internally</string>
<string name="sensor_description_external_storage">Information about the total and available storage space externally</string>
<string name="sensor_description_wifi_connection">Information about the currently connected WiFi network</string> <string name="sensor_description_wifi_connection">Information about the currently connected WiFi network</string>
<string name="sensor_summary">Use this to manage what sensors are enabled/disabled.</string> <string name="sensor_summary">Use this to manage what sensors are enabled/disabled.</string>
<string name="sensor_title">Manage Sensors</string> <string name="sensor_title">Manage Sensors</string>