Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warnings #1867

Merged
merged 2 commits into from Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -43,7 +43,7 @@ class LightControl {
// On HA Core 2021.5 and later brightness detection has changed
// to simplify things in the app lets use both methods for now
val supportedColorModes = entity.attributes["supported_color_modes"] as? List<String>
val supportsBrightness = if (supportedColorModes == null) false else !(supportedColorModes - NO_BRIGHTNESS_SUPPORT).isEmpty()
val supportsBrightness = if (supportedColorModes == null) false else (supportedColorModes - NO_BRIGHTNESS_SUPPORT).isNotEmpty()
control.setTitle((entity.attributes["friendly_name"] ?: entity.entityId) as CharSequence)
control.setDeviceType(DeviceTypes.TYPE_LIGHT)
control.setZone(context.getString(R.string.domain_light))
Expand Down
Expand Up @@ -82,16 +82,14 @@ class LightSensorManager : SensorManager, SensorEventListener {
}

override fun onSensorChanged(event: SensorEvent?) {
if (event != null) {
if (event.sensor.type == Sensor.TYPE_LIGHT) {
onSensorUpdated(
latestContext,
lightSensor,
event.values[0].roundToInt().toString(),
"mdi:brightness-5",
mapOf()
)
}
if (event?.sensor?.type == Sensor.TYPE_LIGHT) {
onSensorUpdated(
latestContext,
lightSensor,
event.values[0].roundToInt().toString(),
"mdi:brightness-5",
mapOf()
)
}
mySensorManager.unregisterListener(this)
Log.d(TAG, "Light sensor listener unregistered")
Expand Down
Expand Up @@ -80,24 +80,21 @@ class ProximitySensorManager : SensorManager, SensorEventListener {
}

override fun onSensorChanged(event: SensorEvent?) {
if (event != null) {
if (event.sensor.type == Sensor.TYPE_PROXIMITY) {
val sensorValue = event.values[0].roundToInt()
val state =
if (maxRange == 5 && sensorValue == 5)
"far"
else if (maxRange == 5)
"near"
else
sensorValue
onSensorUpdated(
latestContext,
proximitySensor,
state,
"mdi:leak",
mapOf()
)
}
if (event?.sensor?.type == Sensor.TYPE_PROXIMITY) {
val sensorValue = event.values[0].roundToInt()
val state =
when {
maxRange == 5 && sensorValue == 5 -> "far"
maxRange == 5 -> "near"
else -> sensorValue
}
onSensorUpdated(
latestContext,
proximitySensor,
state,
"mdi:leak",
mapOf()
)
}
mySensorManager.unregisterListener(this)
Log.d(TAG, "Proximity sensor listener unregistered")
Expand Down
Expand Up @@ -73,9 +73,8 @@ class SensorWorker(
val foregroundInfo = ForegroundInfo(NOTIFICATION_ID, notification)
setForeground(foregroundInfo)
val lastUpdateSensor = sensorDao.get(LastUpdateManager.lastUpdate.id)
if (lastUpdateSensor != null) {
if (lastUpdateSensor.enabled)
LastUpdateManager().sendLastUpdate(appContext, TAG)
if (lastUpdateSensor?.enabled == true) {
LastUpdateManager().sendLastUpdate(appContext, TAG)
}
SensorReceiver().updateSensors(appContext, integrationUseCase)
}
Expand Down
Expand Up @@ -93,16 +93,14 @@ class StepsSensorManager : SensorManager, SensorEventListener {
}

override fun onSensorChanged(event: SensorEvent?) {
if (event != null) {
if (event.sensor.type == Sensor.TYPE_STEP_COUNTER) {
onSensorUpdated(
latestContext,
stepsSensor,
event.values[0].roundToInt().toString(),
"mdi:walk",
mapOf()
)
}
if (event?.sensor?.type == Sensor.TYPE_STEP_COUNTER) {
onSensorUpdated(
latestContext,
stepsSensor,
event.values[0].roundToInt().toString(),
"mdi:walk",
mapOf()
)
}
mySensorManager.unregisterListener(this)
Log.d(TAG, "Steps sensor listener unregistered")
Expand Down
Expand Up @@ -9,9 +9,7 @@ object LocationPermissionInfoHandler {

fun showLocationPermInfoDialogIfNeeded(context: Context, permissions: Array<String>, continueYesCallback: () -> Unit, continueNoCallback: (() -> Unit)? = null) {
if (permissions.any {
it == Manifest.permission.ACCESS_FINE_LOCATION ||
it == Manifest.permission.ACCESS_FINE_LOCATION ||
it == Manifest.permission.ACCESS_BACKGROUND_LOCATION
it == Manifest.permission.ACCESS_FINE_LOCATION || it == Manifest.permission.ACCESS_BACKGROUND_LOCATION
}
) {
AlertDialog.Builder(context)
Expand Down